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:
@@ -697,8 +697,6 @@ def run_from_config(config, out_dir=None):
|
||||
global GRAVITY_FIELD, GRAVITY_INTERACTION, ELASTIC_FORCE, DAMPING_FORCE, GRAVITY_STRENGTH
|
||||
global DRIVING_FORCE, DRIVER_DATA
|
||||
|
||||
global use_marker
|
||||
...
|
||||
box_a = float(config.get("box_a", 10.0))
|
||||
raw_alpha = config.get("alpha", 0.2)
|
||||
if isinstance(raw_alpha, (list, tuple)):
|
||||
|
||||
+12
-1
@@ -238,7 +238,8 @@ def run_case(config_path, runtime_base, input_dir="input", output_dir="output",
|
||||
# 外部引擎写完整 trajectory.txt,后续抽帧
|
||||
traj_x, traj_y, traj_z, traj_vx, traj_vy, traj_vz = compute.run_engine(
|
||||
engine, input_dir_abs, output_dir_abs, config)
|
||||
compute.save_trajectory_txt(traj_x, traj_y, traj_z, traj_vx, traj_vy, traj_vz, str(runtime_base))
|
||||
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))
|
||||
|
||||
_elapsed = _time.time() - _t0
|
||||
print(f"[run] 引擎: {engine} 计算完成: {record_steps} 步 {_elapsed:.3f} s")
|
||||
@@ -309,6 +310,16 @@ 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
|
||||
|
||||
# 4. 绘图(可选)
|
||||
if not no_plot and config.get("step_plot", 1):
|
||||
try:
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
bond_name k rest_length
|
||||
k1 1.0 1.0
|
||||
k1 10.0 1.0
|
||||
|
||||
@@ -72,7 +72,7 @@ T_total: 100.0
|
||||
NSTEP: 100
|
||||
|
||||
# ── 时间步长 ──────────────────────────────────
|
||||
DT: 0.01 # 时间步长 (s)
|
||||
DT: 0.001 # 时间步长 (s)
|
||||
|
||||
# 抽帧范围:只保存 [sample_start, sample_end) 区间内的帧
|
||||
sample_start: null # null 表示从头开始(帧索引从 0 起)
|
||||
|
||||
Reference in New Issue
Block a user