diff --git a/parastell/invessel_build.py b/parastell/invessel_build.py index 419f213a..3ed07be1 100644 --- a/parastell/invessel_build.py +++ b/parastell/invessel_build.py @@ -671,6 +671,8 @@ def radial_build(self, build_dict): } for name, component in self._radial_build.items(): + component['thickness_matrix'] = \ + np.array(component['thickness_matrix']) if ( component['thickness_matrix'].shape != (len(self._toroidal_angles), len(self._poloidal_angles)) @@ -740,6 +742,15 @@ def parse_args(): 'filename', help='YAML file defining ParaStell in-vessel component configuration' ) + parser.add_argument( + '-l', '--logger', + default=False, + help=( + 'Flag to indicate whether to instantiate a logger object (default: ' + 'False)' + ), + metavar='' + ) return parser.parse_args() @@ -761,6 +772,11 @@ def generate_invessel_build(): vmec_file, invessel_build_dict = read_yaml_config(args.filename) + if args.logger == True: + logger = log.init() + else: + logger = log.NullLogger() + vmec_obj = read_vmec.VMECData(vmec_file) rb_allowed_kwargs = ['plasma_mat_tag', 'sol_mat_tag'] @@ -774,6 +790,7 @@ def generate_invessel_build(): invessel_build_dict['poloidal_angles'], invessel_build_dict['wall_s'], invessel_build_dict['radial_build'], + logger=logger **rb_kwargs ) @@ -786,7 +803,7 @@ def generate_invessel_build(): invessel_build = InVesselBuild( vmec_obj, radial_build, - logger=radial_build.logger, + logger=logger, **ivb_kwargs ) diff --git a/parastell/log.py b/parastell/log.py index e0313659..942204e3 100644 --- a/parastell/log.py +++ b/parastell/log.py @@ -1,44 +1,69 @@ import logging +import time +def check_init(logger_obj): + """Checks if a logger object has been instantiated, and if not, + instantiates one. + + Arguments: + logger_obj (object or None): logger object input. + + Returns: + logger_obj (object): logger object. + """ + if logger_obj != None and logger_obj.hasHandlers(): + return logger_obj + else: + return NullLogger() + + +class NullLogger(object): + """Creates a pseudo logger object mimicking an actual logger object whose + methods do nothing when called. + """ + def __init__(self): + pass + + def hasHandlers(self): + return True + + def info(self, message): + current_time = time.localtime() + current_time = time.strftime('%H:%M:%S', current_time) + print(f'{current_time}: {message}') + + def warning(self, *args): + pass + + def error(self, *args): + pass + + def init(): """Creates and configures logger with separate stream and file handlers. Returns: logger (object): logger object. """ - # Create logger logger = logging.getLogger('log') - # Configure base logger message level + logger.setLevel(logging.INFO) - # Configure stream handler + s_handler = logging.StreamHandler() - # Configure file handler - f_handler = logging.FileHandler('stellarator.log') - # Define and set logging format + f_handler = logging.FileHandler( + filename='stellarator.log', + mode='w' + ) + format = logging.Formatter( fmt = '%(asctime)s: %(message)s', datefmt = '%H:%M:%S' ) s_handler.setFormatter(format) f_handler.setFormatter(format) - # Add handlers to logger + logger.addHandler(s_handler) logger.addHandler(f_handler) return logger - - -def check_init(logger_obj): - """Checks if a logger object has been instantiated, and if not, - instantiates one. - - Arguments: - logger_obj (object or None): logger object input. - Returns: - logger_obj (object): logger object. - """ - if logger_obj != None and logger_obj.hasHandlers(): - return logger_obj - else: - return init() diff --git a/parastell/magnet_coils.py b/parastell/magnet_coils.py index 3474a2f8..a1e3e55e 100644 --- a/parastell/magnet_coils.py +++ b/parastell/magnet_coils.py @@ -588,6 +588,15 @@ def parse_args(): parser.add_argument( 'filename', help='YAML file defining ParaStell magnet configuration' ) + parser.add_argument( + '-l', '--logger', + default=False, + help=( + 'Flag to indicate whether to instantiate a logger object (default: ' + 'False)' + ), + metavar='' + ) return parser.parse_args() @@ -609,6 +618,11 @@ def generate_magnet_set(): magnet_coils_dict = read_yaml_config(args.filename) + if args.logger == True: + logger = log.init() + else: + logger = log.NullLogger() + mc_allowed_kwargs = [ 'start_line', 'sample_mod', 'scale', 'mat_tag' ] @@ -621,6 +635,7 @@ def generate_magnet_set(): magnet_coils_dict['coils_file'], magnet_coils_dict['cross_section'], magnet_coils_dict['toroidal_extent'], + logger=logger **mc_kwargs ) diff --git a/parastell/parastell.py b/parastell/parastell.py index 17ade47c..3f88da4f 100644 --- a/parastell/parastell.py +++ b/parastell/parastell.py @@ -467,6 +467,15 @@ def parse_args(): 'filename', help='YAML file defining ParaStell stellarator configuration' ) + parser.add_argument( + '-l', '--logger', + default=False, + help=( + 'Flag to indicate whether to instantiate a logger object (default: ' + 'False)' + ), + metavar='' + ) return parser.parse_args() @@ -494,7 +503,15 @@ def parastell(): vmec_file, invessel_build, magnet_coils, source_mesh, dagmc_export ) = read_yaml_config(args.filename) - stellarator = Stellarator(vmec_file) + if args.logger == True: + logger = log.init() + else: + logger = log.NullLogger() + + stellarator = Stellarator( + vmec_file, + logger=logger + ) # In-Vessel Build diff --git a/parastell/source_mesh.py b/parastell/source_mesh.py index 948cfd8d..fd547c8d 100644 --- a/parastell/source_mesh.py +++ b/parastell/source_mesh.py @@ -409,6 +409,15 @@ def parse_args(): 'filename', help='YAML file defining ParaStell source mesh configuration' ) + parser.add_argument( + '-l', '--logger', + default=False, + help=( + 'Flag to indicate whether to instantiate a logger object (default: ' + 'False)' + ), + metavar='' + ) return parser.parse_args() @@ -430,6 +439,11 @@ def generate_source_mesh(): vmec_file, source_mesh_dict = read_yaml_src(args.filename) + if args.logger == True: + logger = log.init() + else: + logger = log.NullLogger() + vmec_obj = read_vmec.VMECData(vmec_file) sm_allowed_kwargs = ['scale'] @@ -441,7 +455,8 @@ def generate_source_mesh(): source_mesh = SourceMesh( vmec_obj, source_mesh_dict['mesh_size'], - source_mesh_dict['toroidal_extent'] + source_mesh_dict['toroidal_extent'], + logger=logger **sm_kwargs )