Moved execution to run module
This commit is contained in:
parent
79b58cbaf0
commit
476e8b6ada
2 changed files with 26 additions and 91 deletions
|
@ -15,8 +15,7 @@ import urllib.error
|
||||||
|
|
||||||
from .grafana import Silencer
|
from .grafana import Silencer
|
||||||
from .stl import copy_stl
|
from .stl import copy_stl
|
||||||
from .blockmesh import blockmesh
|
from .run import run
|
||||||
from .snappyhexmesh import snappyhexmesh
|
|
||||||
|
|
||||||
|
|
||||||
_t0 = time()
|
_t0 = time()
|
||||||
|
@ -41,6 +40,17 @@ log = logging.getLogger('openfoam')
|
||||||
|
|
||||||
log.info('Starting program')
|
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):
|
if config.getboolean('grafana', 'pause', fallback=False):
|
||||||
log.info('Silencing Grafana alert')
|
log.info('Silencing Grafana alert')
|
||||||
grafana = Silencer(
|
grafana = Silencer(
|
||||||
|
@ -75,20 +85,10 @@ if config.getboolean('stl', 'copy', fallback=False):
|
||||||
copy_stl(stl_in, case_dir)
|
copy_stl(stl_in, case_dir)
|
||||||
|
|
||||||
if config.getboolean('blockMesh', 'enable', fallback=False):
|
if config.getboolean('blockMesh', 'enable', fallback=False):
|
||||||
log.info('Running blockMesh')
|
step(('blockMesh'))
|
||||||
code = blockmesh(case_dir)
|
|
||||||
if code != 0:
|
|
||||||
log.error('blockMesh failed')
|
|
||||||
sys.exit(code)
|
|
||||||
log.info(f'blockMesh finished successfully')
|
|
||||||
|
|
||||||
if config.getboolean('snappyHexMesh', 'enable', fallback=False):
|
if config.getboolean('snappyHexMesh', 'enable', fallback=False):
|
||||||
log.info('Running snappyHexMesh')
|
step(('snappyHexMesh', '-overwrite'), 'snappyHexMesh')
|
||||||
code = snappyhexmesh(case_dir)
|
|
||||||
if code != 0:
|
|
||||||
log.error('snappyHexMesh failed')
|
|
||||||
sys.exit(code)
|
|
||||||
log.info(f'snappyHexMesh finished successfully')
|
|
||||||
|
|
||||||
log.info('Copying 0.org -> 0')
|
log.info('Copying 0.org -> 0')
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
|
@ -97,24 +97,7 @@ shutil.copytree(
|
||||||
)
|
)
|
||||||
|
|
||||||
if config.getboolean('setFields', 'enable', fallback=False):
|
if config.getboolean('setFields', 'enable', fallback=False):
|
||||||
log.info('Running setFields')
|
step(('setFields'))
|
||||||
setfields_log = logging.getLogger('setFields')
|
|
||||||
proc = sp.Popen(
|
|
||||||
('setFields'),
|
|
||||||
cwd=case_dir,
|
|
||||||
stdout=sp.PIPE,
|
|
||||||
stderr=sp.PIPE,
|
|
||||||
text=True,
|
|
||||||
)
|
|
||||||
for line in proc.stdout:
|
|
||||||
setfields_log.info(line[:-1])
|
|
||||||
for line in proc.stderr:
|
|
||||||
setfields_log.info(line[:-1])
|
|
||||||
code = proc.wait()
|
|
||||||
if code != 0:
|
|
||||||
log.error('setFields failed')
|
|
||||||
sys.exit(code)
|
|
||||||
log.info(f'setFields finished successfully')
|
|
||||||
|
|
||||||
if config.getboolean('olaFlow', 'enable', fallback=False):
|
if config.getboolean('olaFlow', 'enable', fallback=False):
|
||||||
cmd = ('olaFlow')
|
cmd = ('olaFlow')
|
||||||
|
@ -124,62 +107,13 @@ if config.getboolean('olaFlow', 'enable', fallback=False):
|
||||||
'-np', config.get('parallel', 'threads'),
|
'-np', config.get('parallel', 'threads'),
|
||||||
'olaFlow', '-parallel'
|
'olaFlow', '-parallel'
|
||||||
)
|
)
|
||||||
decpar_log = logging.getLogger('decomposePar')
|
step(('decomposePar'))
|
||||||
proc = sp.Popen(
|
|
||||||
('decomposePar'),
|
|
||||||
cwd=case_dir,
|
|
||||||
stdout=sp.PIPE,
|
|
||||||
stderr=sp.PIPE,
|
|
||||||
text=True,
|
|
||||||
)
|
|
||||||
for line in proc.stdout:
|
|
||||||
decpar_log.info(line[:-1])
|
|
||||||
for line in proc.stderr:
|
|
||||||
decpar_log.error(line[:-1])
|
|
||||||
code = proc.wait()
|
|
||||||
if code != 0:
|
|
||||||
log.error('decomposePar failed')
|
|
||||||
sys.exit(code)
|
|
||||||
log.info(f'decomposePar finished successfully')
|
|
||||||
|
|
||||||
log.info('Running olaFlow')
|
step(cmd, 'olaFlow')
|
||||||
olaflow_log = logging.getLogger('olaFlow')
|
|
||||||
proc = sp.Popen(
|
|
||||||
cmd,
|
|
||||||
cwd=case_dir,
|
|
||||||
stdout=sp.PIPE,
|
|
||||||
stderr=sp.PIPE,
|
|
||||||
text=True,
|
|
||||||
)
|
|
||||||
for line in proc.stdout:
|
|
||||||
olaflow_log.info(line[:-1])
|
|
||||||
for line in proc.stderr:
|
|
||||||
olaflow_log.error(line[:-1])
|
|
||||||
code = proc.wait()
|
|
||||||
if code != 0:
|
|
||||||
log.error('olaFlow failed')
|
|
||||||
sys.exit(code)
|
|
||||||
log.info(f'olaFlow finished successfully')
|
|
||||||
|
|
||||||
if config.getboolean('parallel', 'enable', fallback=False) \
|
if config.getboolean('parallel', 'enable', fallback=False) \
|
||||||
and config.getboolean('reconstructPar', 'enable', fallback=False):
|
and config.getboolean('reconstructPar', 'enable', fallback=False):
|
||||||
recpar_log = logging.getLogger('reconstructPar')
|
step(('reconstructPar'))
|
||||||
proc = sp.Popen(
|
|
||||||
('reconstructPar'),
|
|
||||||
cwd=case_dir,
|
|
||||||
stdout=sp.PIPE,
|
|
||||||
stderr=sp.PIPE,
|
|
||||||
text=True,
|
|
||||||
)
|
|
||||||
for line in proc.stdout:
|
|
||||||
recpar_log.info(line[:-1])
|
|
||||||
for line in proc.stderr:
|
|
||||||
recpar_log.error(line[:-1])
|
|
||||||
code = proc.wait()
|
|
||||||
if code != 0:
|
|
||||||
log.error('reconstructPar failed')
|
|
||||||
sys.exit(code)
|
|
||||||
log.info(f'reconstructPar finished successfully')
|
|
||||||
|
|
||||||
log.info(f'Deleting processor directories')
|
log.info(f'Deleting processor directories')
|
||||||
for proc_dir in case_dir.glob(r'processor*'):
|
for proc_dir in case_dir.glob(r'processor*'):
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
def blockmesh(case_dir):
|
def run(command, case, alias=None):
|
||||||
blockmesh_log = logging.getLogger('blockMesh')
|
if alias == None: alias = command
|
||||||
|
log = logging.getLogger(alias)
|
||||||
proc = sp.Popen(
|
proc = sp.Popen(
|
||||||
('blockMesh'),
|
command,
|
||||||
cwd=case_dir,
|
cwd=case,
|
||||||
stdout=sp.PIPE,
|
stdout=sp.PIPE,
|
||||||
stderr=sp.PIPE,
|
stderr=sp.PIPE,
|
||||||
text=True,
|
text=True,
|
||||||
)
|
)
|
||||||
for line in proc.stdout:
|
for line in proc.stdout:
|
||||||
blockmesh_log.info(line[:-1])
|
log.info(line[:-1])
|
||||||
for line in proc.stderr:
|
for line in proc.stderr:
|
||||||
blockmesh_log.error(line[:-1])
|
log.info(line[:-1])
|
||||||
return proc.wait()
|
return proc.wait()
|
Reference in a new issue