From 0330a0d32dd6f5875c5baeb227ccf71bd238e4f1 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 23 Jan 2022 13:16:00 +0100 Subject: [PATCH] Added fallback values for openfoam run config --- openfoam/artha/constant/triSurface/.gitignore | 1 - openfoam/artha/system/setFieldsDict | 2 +- openfoam/config.example.ini | 6 ++- openfoam/run/__main__.py | 37 +++++++++++++------ 4 files changed, 31 insertions(+), 15 deletions(-) delete mode 100644 openfoam/artha/constant/triSurface/.gitignore diff --git a/openfoam/artha/constant/triSurface/.gitignore b/openfoam/artha/constant/triSurface/.gitignore deleted file mode 100644 index 1567411..0000000 --- a/openfoam/artha/constant/triSurface/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.stl diff --git a/openfoam/artha/system/setFieldsDict b/openfoam/artha/system/setFieldsDict index 30aa755..1cb3097 100644 --- a/openfoam/artha/system/setFieldsDict +++ b/openfoam/artha/system/setFieldsDict @@ -34,7 +34,7 @@ regions } surfaceToCell { - file "./constant/triSurface/rub.stl"; + file "./constant/triSurface/rubble.stl"; outsidePoints ((0 0 0)); // definition of outside includeCut true; // cells cut by surface includeInside true; // cells not on outside of surf diff --git a/openfoam/config.example.ini b/openfoam/config.example.ini index f797a64..16171ce 100644 --- a/openfoam/config.example.ini +++ b/openfoam/config.example.ini @@ -4,6 +4,10 @@ work_dir = /home/masterccce/OpenFOAM/work case = artha #log_file = openfoam.log +[stl] +copy = True +from = ../bathymetry/2_stl + [blockMesh] enable = True [snappyHexMesh] @@ -13,7 +17,7 @@ enable = True [olaFlow] enable = True [parallel] -enable = False +enable = True threads = 4 [reconstructPar] enable = True diff --git a/openfoam/run/__main__.py b/openfoam/run/__main__.py index be2b1cf..d157929 100644 --- a/openfoam/run/__main__.py +++ b/openfoam/run/__main__.py @@ -26,21 +26,21 @@ config = configparser.ConfigParser() config.read(args.config) logging.basicConfig( - filename=config['main'].get('log_file', None), + filename=config.get('main', 'log_file', fallback=None), level=args.log_level ) log = logging.getLogger('openfoam') log.info('Starting program') -input_dir = Path(config['main']['input_dir'], config['main']['case']) -work_dir = Path(config['main']['work_dir']) +input_dir = Path(config.get('main', 'input_dir'), config.get('main', 'case')) +work_dir = Path(config.get('main', 'work_dir')) if not work_dir.exists(): log.error(f'Work directory ({work_dir}) not found') sys.exit(1) -case_dir = work_dir.joinpath(config['main']['case']) +case_dir = work_dir.joinpath(config.get('main', 'case')) if case_dir.exists(): log.info(f'Deleting case ({case_dir})') dir_util.remove_tree(str(case_dir)) @@ -51,7 +51,20 @@ dir_util.copy_tree( str(case_dir), ) -if config['blockMesh'].getboolean('enable'): +if config.getboolean('stl', 'copy', fallback=False): + stl_dir = case_dir.joinpath('constant', 'triSurface') + if stl_dir.exists(): + log.info(f'Deleting stl directory ({stl_dir})') + dir_util.remove_tree(str(stl_dir)) + + stl_in = Path(config.get('stl', 'from')) + log.info(f'Copying stl directory ({stl_in} -> {stl_dir})') + dir_util.copy_tree( + str(stl_in), + str(stl_dir), + ) + +if config.getboolean('blockMesh', 'enable', fallback=False): log.info('Running blockMesh') blockmesh_log = logging.getLogger('blockMesh') proc = sp.Popen( @@ -71,7 +84,7 @@ if config['blockMesh'].getboolean('enable'): sys.exit(code) log.info(f'blockMesh finished successfully') -if config['snappyHexMesh'].getboolean('enable'): +if config.getboolean('snappyHexMesh', 'enable', fallback=False): log.info('Running snappyHexMesh') snappy_log = logging.getLogger('snappyHexMesh') proc = sp.Popen( @@ -97,7 +110,7 @@ dir_util.copy_tree( str(case_dir.joinpath('0')), ) -if config['setFields'].getboolean('enable'): +if config.getboolean('setFields', 'enable', fallback=False): log.info('Running setFields') setfields_log = logging.getLogger('setFields') proc = sp.Popen( @@ -117,12 +130,12 @@ if config['setFields'].getboolean('enable'): sys.exit(code) log.info(f'setFields finished successfully') -if config['olaFlow'].getboolean('enable'): +if config.getboolean('olaFlow', 'enable', fallback=False): cmd = ('olaFlow') - if config['parallel'].getboolean('enable'): + if config.getboolean('parallel', 'enable', fallback=False): cmd = ( 'mpirun', - '-np', config['parallel'].getint('threads'), + '-np', config.get('parallel', 'threads'), 'olaFlow', '-parallel' ) decpar_log = logging.getLogger('decomposePar') @@ -162,8 +175,8 @@ if config['olaFlow'].getboolean('enable'): sys.exit(code) log.info(f'olaFlow finished successfully') - if config['parallel'].getboolean('enable') \ - and config['reconstructPar'].getboolean('enable'): + if config.getboolean('parallel', 'enable', fallback=False) \ + and config.getboolean('reconstructPar', 'enable', fallback=False): recpar_log = logging.getLogger('reconstructPar') proc = sp.Popen( ('reconstructPar'),