80520590d1
- 创建 plot_wave.py: 从 display.txt 读取原子位移数据 绘制纵波(x) + 横波(y) + 横波(z) 波形随时间的动画 同时绘制系统动能/弹性势能/总能量/输入功率(dE/dt)时变曲线 输出 wave_animation.gif - 所有 input.txt 新增 step_plot_wave: 0 开关 - case05 开启 step_plot_wave: 1 - dynamics.py disp_data 新增 bond_stiffness/bond_rest_lengths - 更新案例文档
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
"""
|
|
Case runner for Dynamics case05 — 1D atomic chain.
|
|
|
|
This script keeps program and data separated:
|
|
- program: ../../dynamics.py
|
|
- input: ./input
|
|
- output: ./output
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import importlib.util
|
|
from pathlib import Path
|
|
|
|
|
|
CASE_DIR = Path(__file__).resolve().parent
|
|
DYNAMICS_PATH = Path("..") / ".." / "dynamics.py"
|
|
INPUT_DIR = Path("input")
|
|
OUTPUT_DIR = Path("output")
|
|
CONFIG_FILE = INPUT_DIR / "input.txt"
|
|
|
|
|
|
def load_dynamics_module(module_path: Path):
|
|
spec = importlib.util.spec_from_file_location("dynamics_module", module_path)
|
|
if spec is None or spec.loader is None:
|
|
raise ImportError(f"无法加载 dynamics.py: {module_path}")
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="运行 Dynamics 示例案例 case01")
|
|
parser.add_argument("--no-plot", action="store_true", help="跳过 matplotlib 绘图")
|
|
args = parser.parse_args()
|
|
|
|
dynamics_path = (CASE_DIR / DYNAMICS_PATH).resolve()
|
|
input_dir = (CASE_DIR / INPUT_DIR).resolve()
|
|
output_dir = (CASE_DIR / OUTPUT_DIR).resolve()
|
|
config_path = (CASE_DIR / CONFIG_FILE).resolve()
|
|
|
|
module = load_dynamics_module(dynamics_path)
|
|
module.run_case(
|
|
config_path=config_path,
|
|
runtime_base=CASE_DIR,
|
|
input_dir=input_dir,
|
|
output_dir=output_dir,
|
|
no_plot=args.no_plot,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|