PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
convert_grid_from_legacy_to_picgrid.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""Backward-compatible wrapper for legacy grid conversion.
3
4This script now delegates to:
5 python3 scripts/grid.gen legacy1d ...
6so there is a single maintained conversion implementation.
7"""
8
9from __future__ import annotations
10
11import argparse
12import os
13import subprocess
14import sys
15
16
17def parse_args() -> argparse.Namespace:
18 """!
19 @brief Parse wrapper CLI arguments.
20 @return Value returned by `parse_args()`.
21 """
22 parser = argparse.ArgumentParser(
23 description="Convert a legacy 1D-axis grid payload into canonical PICGRID format.",
24 formatter_class=argparse.RawDescriptionHelpFormatter,
25 epilog=(
26 "This wrapper delegates to: python3 scripts/grid.gen legacy1d ...\n\n"
27 "Examples:\n"
28 " python3 scripts/convert_grid_from_legacy_to_picgrid.py \\\n"
29 " --input legacy_flat.grid --output converted.picgrid\n"
30 " python3 scripts/convert_grid_from_legacy_to_picgrid.py \\\n"
31 " --input legacy_flat.grid --output converted.picgrid --axis-columns 0 1 2\n"
32 " python3 scripts/convert_grid_from_legacy_to_picgrid.py \\\n"
33 " --input legacy_flat.grid --output converted.picgrid --allow-trailing\n"
34 ),
35 )
36 parser.add_argument("--input", required=True, help="Path to legacy grid input file.")
37 parser.add_argument("--output", required=True, help="Path to converted PICGRID output file.")
38 parser.add_argument(
39 "--axis-columns",
40 type=int,
41 nargs=3,
42 default=[0, 1, 2],
43 metavar=("XCOL", "YCOL", "ZCOL"),
44 help="Preferred source column index for X/Y/Z axis rows (default: 0 1 2).",
45 )
46 parser.add_argument(
47 "--allow-trailing",
48 action="store_true",
49 help="Ignore trailing payload rows after expected legacy content.",
50 )
51 return parser.parse_args()
52
53
54def main() -> int:
55 """!
56 @brief Entry point.
57 @return Value returned by `main()`.
58 """
59 args = parse_args()
60 script_dir = os.path.dirname(os.path.abspath(__file__))
61 gridgen = os.path.join(script_dir, "grid.gen")
62 if not os.path.isfile(gridgen):
63 print(f"Error: grid.gen not found at '{gridgen}'.", file=sys.stderr)
64 return 1
65
66 cmd = [
67 sys.executable,
68 gridgen,
69 "legacy1d",
70 "--input",
71 args.input,
72 "--output",
73 args.output,
74 "--axis-columns",
75 str(args.axis_columns[0]),
76 str(args.axis_columns[1]),
77 str(args.axis_columns[2]),
78 "--no-write-vtk",
79 ]
80 cmd.append("--allow-trailing" if args.allow_trailing else "--strict-trailing")
81
82 result = subprocess.run(cmd, text=True, capture_output=True)
83 if result.stdout:
84 print(result.stdout.strip())
85 if result.stderr:
86 print(result.stderr.strip(), file=sys.stderr)
87 return result.returncode
88
89
90if __name__ == "__main__":
91 raise SystemExit(main())
argparse.Namespace parse_args()
Parse wrapper CLI arguments.