From db50ac6d4de6fb0c829913b81b3cee2d985918cf Mon Sep 17 00:00:00 2001 From: Ying-Li Niu <64801511@qq.com> Date: Thu, 11 Jun 2026 21:36:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=96=E9=83=A8=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E8=BF=9B=E5=BA=A6=E6=9D=A1=20+=20C=E5=BC=95?= =?UTF-8?q?=E6=93=8Eread=5Fbonds=20rewind=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 引擎端:C/C++/Fortran 主循环每 1% 输出 progress 到 stdout 2. compute.py:读取 "[xxx] progress: N/total" 行更新 tqdm 3. 移除不准的时间估算逻辑,改用真实引擎进度 4. C引擎 read_bonds:rewind 后补 fgets 跳表头 5. gitignore 添加 output_test/ --- compute.py | 12 +++++++++--- engines/c/main.c | 6 ++++++ engines/cpp/main.cpp | 5 +++++ engines/fortran/main.f90 | 7 ++++++- examples/case06/input/input.txt | 2 +- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/compute.py b/compute.py index 3592bed..878255c 100644 --- a/compute.py +++ b/compute.py @@ -10,6 +10,7 @@ compute.py """ import json +import re import numpy as np import os import platform @@ -760,6 +761,14 @@ def run_engine(engine, input_dir, output_dir, config): _line = _line.strip() if _line: _engine_lines.append(_line) + # 读取外部引擎真实进度:格式 "[xxx-engine] progress: N/total" + _prog_match = re.search(r'progress:\s*(\d+)/(\d+)', _line) + if _pbar is not None and _prog_match: + _prog_done = int(_prog_match.group(1)) + _prog_total = int(_prog_match.group(2)) + if _prog_total > 0: + _pbar.n = min(_prog_done, total_steps) + _pbar.refresh() if _p.poll() is not None: if _p.stdout: for _r in _p.stdout: @@ -767,9 +776,6 @@ def run_engine(engine, input_dir, output_dir, config): if _r: _engine_lines.append(_r) break - if _pbar is not None and _est_total > 0: - _pbar.n = int(min((time.time() - t_start) / _est_total, 0.99) * total_steps) - _pbar.refresh() time.sleep(0.2) finally: if _pbar is not None: diff --git a/engines/c/main.c b/engines/c/main.c index a3c794f..6242f79 100644 --- a/engines/c/main.c +++ b/engines/c/main.c @@ -926,7 +926,13 @@ int main(int argc, char **argv) { } /* 记录 */ + int _prog_interval = record_steps / 100; + if (_prog_interval < 1) _prog_interval = 1; for (int s = 0; s < record_steps; s++) { + if (s % _prog_interval == 0 && s > 0) { + printf("[C-engine] progress: %d/%d\n", s, record_steps); + fflush(stdout); + } double t = (s + params.warmup_steps) * params.DT; if (params.driving_force) apply_driving_force(n, x, y, z, vx, vy, vz, t, s, params.DT, &drivers); for (int i = 0; i < n; i++) { diff --git a/engines/cpp/main.cpp b/engines/cpp/main.cpp index e00e4f6..62353c3 100644 --- a/engines/cpp/main.cpp +++ b/engines/cpp/main.cpp @@ -843,7 +843,12 @@ int main(int argc, char **argv) { } // 记录 + int _prog_int = record_steps / 100; + if (_prog_int < 1) _prog_int = 1; for (int s = 0; s < record_steps; s++) { + if (s % _prog_int == 0 && s > 0) { + std::cout << "[Cpp-engine] progress: " << s << "/" << record_steps << std::endl; + } double t = (s + params.warmup_steps) * params.DT; if (params.driving_force) apply_driving_force(n, x.data(), y.data(), z.data(), vx.data(), vy.data(), vz.data(), t, s, params.DT, drivers); diff --git a/engines/fortran/main.f90 b/engines/fortran/main.f90 index 0d9e909..9de8257 100644 --- a/engines/fortran/main.f90 +++ b/engines/fortran/main.f90 @@ -34,7 +34,7 @@ program dynamics_f90 double precision, allocatable :: bond_stiffness(:), bond_rest_lengths(:) ! 驱动力数据 - integer :: n_drivers + integer :: n_drivers, prog_step integer, allocatable :: drv_atom_idx(:) double precision, allocatable :: drv_amp_x(:), drv_amp_y(:), drv_amp_z(:) double precision, allocatable :: drv_freq_x(:), drv_freq_y(:), drv_freq_z(:) @@ -139,7 +139,12 @@ program dynamics_f90 end do ! 记录 + prog_step = record_steps / 100 + if (prog_step < 1) prog_step = 1 do s = 1, record_steps + if (mod(s, prog_step) == 0 .and. s > 0) then + write(*, '("[Fortran-engine] progress: ", i0, "/", i0)') s, record_steps + end if if (driving_force /= 0 .and. n_drivers > 0) then tw = ((s-1 + warmup_steps) * 1.0d0) * DT call apply_driving(n, x, y, z, vx, vy, vz, tw, s-1, DT, & diff --git a/examples/case06/input/input.txt b/examples/case06/input/input.txt index c224d3d..00f47c5 100644 --- a/examples/case06/input/input.txt +++ b/examples/case06/input/input.txt @@ -63,7 +63,7 @@ warmup_steps: 0 # 默认 0(立即开始记录) # 总模拟时间(秒),程序自动计算 NT = T_total / DT # 如果同时指定了 NT,以 NT 为准 -T_total: 10.0 +T_total: 50.0 # 抽帧间隔(每 NSTEP 步取一帧用于动画) NSTEP: 100