5de80d4f7e
modified: INSTALL.md modified: README.md modified: build_release_zip.py modified: compute.py new file: doc/index.html modified: dynamics.py modified: engines/c/main.c modified: engines/cpp/main.cpp modified: engines/fortran/main.f90 modified: examples/case01/input/coord.txt renamed: examples/case01/input/parameters.yaml -> examples/case01/input/input.txt modified: examples/case01/run_dynamics.py new file: examples/case02/input/bond.txt new file: examples/case02/input/connection.txt new file: examples/case02/input/coord.txt new file: examples/case02/input/input.txt new file: examples/case02/run_dynamics.py
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
"""
|
|
Case runner for Dynamics case01.
|
|
|
|
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()
|