feat: C/C++ 引擎支持 save_trajectory=0 时直接写 display.txt

所有引擎(Python/C/C++)在 save_trajectory=0 时行为一致:
- 计算时按 NSTEP 抽帧,只存 sampled 缓冲区
- 直接写入 display.txt(新文本格式)
- 不生成 trajectory.txt

Python 引擎:run_simulation 已支持 
C 引擎:采样缓冲区 + write_display_txt 
C++ 引擎:采样缓冲区 + write_display_txt 
Fortran 引擎:待完成

compute.py run_engine:save_trajectory=0 时跳过 trajectory.txt 加载
dynamics.py:引擎直接输出 display.txt 时跳过抽帧步骤
This commit is contained in:
2026-06-12 08:25:27 +08:00
parent 41790a782a
commit dc7bc00616
4 changed files with 195 additions and 51 deletions
+14 -16
View File
@@ -246,15 +246,15 @@ def run_case(config_path, runtime_base, input_dir="input", output_dir="output",
else:
print("[run] 步骤 [模拟] 已跳过")
# 3. 生成 display.txt:模拟完成后总是刷新,避免参数变更后缓存过时
# 3. 检查/生成 display.txt
disp_path_new = os.path.join(output_dir_abs, "display.txt")
save_traj = int(config.get("save_trajectory", 0))
if engine == "python":
# Python 引擎在 run_simulation 内部已写入 display.txt
if os.path.exists(disp_path_new):
print(f"[run] 发现已有 display.txt(引擎直接抽帧)")
else:
# 外部引擎:从 trajectory.txt 重新抽帧(覆盖旧的 display.txt
if os.path.exists(disp_path_new):
# Python 引擎或新版外部引擎(save_trajectory=0)已直接写入
print(f"[run] 发现已有 display.txt(引擎直接抽帧)")
elif engine != "python" and os.path.exists(os.path.join(output_dir_abs, "trajectory.txt")):
# 旧版外部引擎:从 trajectory.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")
@@ -310,15 +310,13 @@ def run_case(config_path, runtime_base, input_dir="input", output_dir="output",
header_fields=hf)
print(f"[run] 从 trajectory.txt 抽帧生成 display.txt ({n_frames} 帧)")
# 外部引擎:save_trajectory=0 时清理 trajectory.txt
save_traj = int(config.get("save_trajectory", 0))
if engine != "python" and not save_traj:
traj_path = os.path.join(output_dir_abs, "trajectory.txt")
try:
os.remove(traj_path)
print(f"[run] save_trajectory=0,已删除 {traj_path}")
except OSError:
pass
# save_trajectory=0 时清理 trajectory.txt
if not save_traj:
try:
os.remove(traj_path)
print(f"[run] save_trajectory=0,已删除 {traj_path}")
except OSError:
pass
# 4. 绘图(可选)
if not no_plot and config.get("step_plot", 1):