Simple error log file written when exceptions occur
@@ -31,6 +31,9 @@ def main(args=None, sharpy_input_dict=None):
import sharpy.utils.solver_interface as solver_interface
from sharpy.presharpy.presharpy import PreSharpy
from sharpy.utils.cout_utils import start_writer, finish_writer
+ import logging
+ import os
+
# Loading solvers and postprocessors
import sharpy.solvers
import sharpy.postproc
@@ -38,6 +41,7 @@ def main(args=None, sharpy_input_dict=None):
import sharpy.controllers
# ------------
+ try:
# output writer
start_writer()
# timing
@@ -47,10 +51,12 @@ def main(args=None, sharpy_input_dict=None):
if sharpy_input_dict is None:
parser = argparse.ArgumentParser(prog='SHARPy', description=
"""This is the executable for Simulation of High Aspect Ratio Planes.\n
- Imperial College London 2019""")
+ Imperial College London 2020""")
parser.add_argument('input_filename', help='path to the *.sharpy input file', type=str, default='')
- parser.add_argument('-r', '--restart', help='restart the solution with a given snapshot', type=str, default=None)
- parser.add_argument('-d', '--docs', help='generates the solver documentation in the specified location. Code does not execute if running this flag', action='store_true')
+ parser.add_argument('-r', '--restart', help='restart the solution with a given snapshot', type=str,
+ default=None)
+ parser.add_argument('-d', '--docs', help='generates the solver documentation in the specified location. '
+ 'Code does not execute if running this flag', action='store_true')
if args is not None:
args = parser.parse_args(args[1:])
else:
@@ -71,7 +77,7 @@ def main(args=None, sharpy_input_dict=None):
return 0
if args.input_filename == '':
- parser.error('input_filename is a required argument of sharpy.')
+ parser.error('input_filename is a required argument of SHARPy.')
settings = input_arg.read_settings(args)
if args.restart is None:
# run preSHARPy
@@ -86,11 +92,6 @@ def main(args=None, sharpy_input_dict=None):
# update the settings
data.update_settings(settings)
- # else:
- # # Case for input from dictionary
- # settings = input_arg.read_settings(args)
- # # run preSHARPy
- # data = PreSharpy(settings)
# Loop for the solvers specified in *.sharpy['SHARPy']['flow']
for solver_name in settings['SHARPy']['flow']:
@@ -103,4 +104,24 @@ def main(args=None, sharpy_input_dict=None):
cout.cout_wrap('FINISHED - Elapsed time = %f6 seconds' % wall_time, 2)
cout.cout_wrap('FINISHED - CPU process time = %f6 seconds' % cpu_time, 2)
finish_writer()
+
+ except Exception as e:
+ try:
+ logdir = settings['SHARPy']['log_folder']
+ except KeyError:
+ logdir = './'
+ except NameError:
+ logdir = './'
+ logdir = os.path.abspath(logdir)
+ print('Exception raised, writing error log in %s/error.log' % logdir)
+ logging.basicConfig(filename='%s/error.txt' % logdir,
+ filemode='w',
+ format='%(asctime)s-%(levelname)s-%(message)s',
+ datefmt='%d-%b-%y %H:%M:%S',
+ level=logging.INFO)
+ logging.info('SHARPy Error Log')
+ logging.error("Exception occurred", exc_info=True)
+ raise e
+
return data
+
