-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathfoambench_main.py
More file actions
91 lines (79 loc) · 2.97 KB
/
foambench_main.py
File metadata and controls
91 lines (79 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import subprocess
import sys
import argparse
import shlex
def parse_args():
parser = argparse.ArgumentParser(description="Benchmark Workflow Interface")
base_dir = os.path.dirname(os.path.abspath(__file__))
parser.add_argument(
'--openfoam_path',
type=str,
required=False,
help="Path to OpenFOAM installation (WM_PROJECT_DIR)"
)
parser.add_argument(
'--output',
type=str,
required=False,
default=os.path.join(base_dir, "output"),
help="Base output directory for benchmark results (default: <dir_of_foambench_main.py>/output)"
)
parser.add_argument(
'--prompt_path',
type=str,
required=False,
default=os.path.join(base_dir, "user_requirement.txt"),
help="User requirement file path for the benchmark (default: <dir_of_foambench_main.py>/user_requirement.txt)"
)
parser.add_argument(
'--custom_mesh_path',
type=str,
default=None,
help="Path to custom mesh file (e.g., .msh, .stl, .obj). If not provided, no custom mesh will be used."
)
return parser.parse_args()
def run_command(command_str):
"""
Execute a command string using the current terminal's input/output,
with the working directory set to the directory of the current file.
Parameters:
command_str (str): The command to execute, e.g. "python main.py --output_dir xxxx"
or "bash xxxxx.sh".
"""
# Split the command string into a list of arguments
args = shlex.split(command_str)
# Set the working directory to the directory of the current file
cwd = os.path.dirname(os.path.abspath(__file__))
try:
result = subprocess.run(
args,
cwd=cwd,
check=True,
stdout=sys.stdout,
stderr=sys.stderr,
stdin=sys.stdin
)
print(f"Finished command: Return Code {result.returncode}")
except subprocess.CalledProcessError as e:
print(f"Error running command: {e}")
sys.exit(e.returncode)
def main():
args = parse_args()
print(args)
# Create the output folder
os.makedirs(args.output, exist_ok=True)
# Build main workflow command with optional custom mesh path
main_cmd = f"python src/main.py --prompt_path='{args.prompt_path}' --output_dir='{args.output}'"
if args.custom_mesh_path:
main_cmd += f" --custom_mesh_path='{args.custom_mesh_path}'"
print(f"Main workflow command: {main_cmd}")
print("Starting workflow...")
run_command(main_cmd)
print("Workflow command finished.")
if __name__ == "__main__":
# Examples (paths are resolved relative to the directory containing this file):
# python foambench_main.py
# python foambench_main.py --output output --prompt_path user_requirement.txt
# python foambench_main.py --output output --prompt_path user_requirement.txt --custom_mesh_path my_mesh.msh
main()