fix: save_trajectory=0 时删除 trajectory.txt,所有引擎保持一致

Python 引擎:run_simulation 已正确支持 save_trajectory 
外部引擎(C/C++/Fortran):save_trajectory_txt 仅在
  save_trajectory=1 时调用;display.txt 生成后删除 trajectory.txt
补充:移除 compute.py 中重复的 'global use_marker' 和占位符
This commit is contained in:
2026-06-12 08:18:07 +08:00
parent 6298ed5b34
commit 41790a782a
4 changed files with 14 additions and 5 deletions
-2
View File
@@ -697,8 +697,6 @@ def run_from_config(config, out_dir=None):
global GRAVITY_FIELD, GRAVITY_INTERACTION, ELASTIC_FORCE, DAMPING_FORCE, GRAVITY_STRENGTH global GRAVITY_FIELD, GRAVITY_INTERACTION, ELASTIC_FORCE, DAMPING_FORCE, GRAVITY_STRENGTH
global DRIVING_FORCE, DRIVER_DATA global DRIVING_FORCE, DRIVER_DATA
global use_marker
...
box_a = float(config.get("box_a", 10.0)) box_a = float(config.get("box_a", 10.0))
raw_alpha = config.get("alpha", 0.2) raw_alpha = config.get("alpha", 0.2)
if isinstance(raw_alpha, (list, tuple)): if isinstance(raw_alpha, (list, tuple)):
+11
View File
@@ -238,6 +238,7 @@ def run_case(config_path, runtime_base, input_dir="input", output_dir="output",
# 外部引擎写完整 trajectory.txt,后续抽帧 # 外部引擎写完整 trajectory.txt,后续抽帧
traj_x, traj_y, traj_z, traj_vx, traj_vy, traj_vz = compute.run_engine( traj_x, traj_y, traj_z, traj_vx, traj_vy, traj_vz = compute.run_engine(
engine, input_dir_abs, output_dir_abs, config) engine, input_dir_abs, output_dir_abs, config)
if int(config.get("save_trajectory", 0)):
compute.save_trajectory_txt(traj_x, traj_y, traj_z, traj_vx, traj_vy, traj_vz, str(runtime_base)) compute.save_trajectory_txt(traj_x, traj_y, traj_z, traj_vx, traj_vy, traj_vz, str(runtime_base))
_elapsed = _time.time() - _t0 _elapsed = _time.time() - _t0
@@ -309,6 +310,16 @@ def run_case(config_path, runtime_base, input_dir="input", output_dir="output",
header_fields=hf) header_fields=hf)
print(f"[run] 从 trajectory.txt 抽帧生成 display.txt ({n_frames} 帧)") 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
# 4. 绘图(可选) # 4. 绘图(可选)
if not no_plot and config.get("step_plot", 1): if not no_plot and config.get("step_plot", 1):
try: try:
+1 -1
View File
@@ -1,2 +1,2 @@
bond_name k rest_length bond_name k rest_length
k1 1.0 1.0 k1 10.0 1.0
+1 -1
View File
@@ -72,7 +72,7 @@ T_total: 100.0
NSTEP: 100 NSTEP: 100
# ── 时间步长 ────────────────────────────────── # ── 时间步长 ──────────────────────────────────
DT: 0.01 # 时间步长 (s) DT: 0.001 # 时间步长 (s)
# 抽帧范围:只保存 [sample_start, sample_end) 区间内的帧 # 抽帧范围:只保存 [sample_start, sample_end) 区间内的帧
sample_start: null # null 表示从头开始(帧索引从 0 起) sample_start: null # null 表示从头开始(帧索引从 0 起)