From 6c00ca117e20d164fd56b66c47e28b56093f168c Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Wed, 26 Jan 2022 18:38:46 +0100 Subject: [PATCH] Minor tweaks --- README.md | 15 +++++++++++++++ openfoam/run/__main__.py | 26 ++++++++++++++------------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c7e1fee..0df2f17 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,29 @@ in 2017. The `bathymetry` directory contains the raw data and a tool that allows to generate the stl files necessary for the OpenFoam model. +Usage: +``` +python -m generate +``` + ### OpenFoam The `openfoam` directory contains the OpenFoam configuration files and a utility that copies the configuration and runs the `olaFlow` model. +Usage: +``` +python -m run +``` + ### Post-process The `post_process` directory provides a utility for plotting an animation of the simulation. +Usage: +``` +python -m animate alpha.water +``` + ## Requirements The required Python packages are listed in the `requirements.txt` file. Run `pip install -r requirements.txt` to install all the required packages. diff --git a/openfoam/run/__main__.py b/openfoam/run/__main__.py index 84c3336..8557219 100644 --- a/openfoam/run/__main__.py +++ b/openfoam/run/__main__.py @@ -16,10 +16,11 @@ from .run import run _t0 = time() parser = argparse.ArgumentParser( - description='Run the OpenFoam simulation' + prog='run', + description='Run the OpenFoam simulation', ) parser.add_argument('-c', '--config', default='config.ini', type=Path, - help='Configuration file (default config.ini)') + help='Configuration file') parser.add_argument('-l', '--log-level', default='INFO', type=str, help='Log level') @@ -37,16 +38,6 @@ log = logging.getLogger('openfoam') log.info('Starting program') -def step(command, alias=None): - if alias == None: alias = command - log.info(f'Running {alias}') - code = run(command, case_dir, alias) - if code != 0: - log.error(f'{alias} failed') - sys.exit(code) - log.info(f'{alias} finished successfully') - - if config.getboolean('grafana', 'pause', fallback=False): log.info('Silencing Grafana alert') grafana = Silencer( @@ -71,6 +62,17 @@ if case_dir.exists(): log.info(f'Copying case ({input_dir} -> {case_dir})') shutil.copytree(input_dir, case_dir) + +def step(command, alias=None): + if alias == None: alias = command + log.info(f'Running {alias}') + code = run(command, case_dir, alias) + if code != 0: + log.error(f'{alias} failed') + sys.exit(code) + log.info(f'{alias} finished successfully') + + if config.getboolean('stl', 'copy', fallback=False): stl_in = Path(config.get('stl', 'from')).expanduser() if not stl_in.exists():