48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
|
import argparse
|
||
|
import configparser
|
||
|
import logging
|
||
|
import os
|
||
|
import pathlib
|
||
|
import shutil
|
||
|
from subprocess import run, STDOUT
|
||
|
|
||
|
parser = argparse.ArgumentParser(description="Run olaFlow model")
|
||
|
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||
|
parser.add_argument("-c", "--config", default="config.ini")
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
|
||
|
log = logging.getLogger("sws_ola")
|
||
|
|
||
|
log.info("Starting olaFlow model")
|
||
|
config = configparser.ConfigParser()
|
||
|
config.read(args.config)
|
||
|
|
||
|
root = pathlib.Path(config.get("olaflow", "root"))
|
||
|
out = pathlib.Path(config.get("olaflow", "out"))
|
||
|
logs = out.joinpath("log")
|
||
|
|
||
|
shutil.copytree(root, out)
|
||
|
logs.mkdir()
|
||
|
|
||
|
path = config.get("olaflow", "path")
|
||
|
env = {"PATH": f"{path}:{os.environ['PATH']}"}
|
||
|
|
||
|
def ola_run(cmd):
|
||
|
with logs.joinpath(f"{cmd[0]}.log").open("wt") as logfile:
|
||
|
run(
|
||
|
cmd,
|
||
|
cwd=out,
|
||
|
env=env,
|
||
|
stdout=logfile,
|
||
|
stderr=STDOUT,
|
||
|
).check_returncode()
|
||
|
|
||
|
ola_run(("blockMesh",))
|
||
|
ola_run(("snappyHexMesh", "-overwrite"))
|
||
|
shutil.copytree(root.joinpath("0.org"), root.joinpath("0"))
|
||
|
ola_run(("setFields",))
|
||
|
ola_run(("decomposePar",))
|
||
|
ola_run(("mpirun", "-np", "4", "olaFlow", "-parallel"))
|
||
|
ola_run(("reconstructPar",))
|