def add_from_data_lines(cls, param_map: Dict[str, str], data_lines: List[str], log: SimpleLogger): material_name = param_map['material'] #print('param_map =', param_map) elset = param_map.get('elset', None) log.debug(f'material_name = {material_name}') param_map = param_map data_lines = data_lines thickness = 0. #print('param_map =', param_map) if len(data_lines) == 0: pass elif len(data_lines) == 1: assert len(data_lines) == 1, data_lines line0 = data_lines[0] assert len(line0) == 1, data_lines try: thickness = float(line0[0]) except ValueError: pass for line in data_lines: log.info('solid - %r' % line) return SolidSection(material_name, elset, thickness, log)
def cast_nodes(nids: List[Any], nodes: List[Any], log: SimpleLogger, require: bool = True) -> Tuple[np.ndarray, np.ndarray]: if len(nids) == 0 and require == False: assert len(nodes) == 0, len(nodes) return None, None try: nids = np.array(nids, dtype='int32') except ValueError: msg = 'nids=%s is not integers' % nids raise ValueError(msg) nnodes = len(nids) node0 = nodes[0] node_shape = len(node0) if node_shape == 3: nodes = np.array(nodes, dtype='float32') log.info(f'3d model found; nodes.shape={nodes.shape}') elif node_shape == 2: # abaqus can have only x/y coordinates, so we fake the z coordinate nodes = np.zeros((nnodes, 3), dtype='float32') nodes2 = np.array(nodes, dtype='float32') #print(nodes2.shape, self.nodes.shape) nodes[:, :2] = nodes2 log.info(f'2d model found; nodes.shape={nodes.shape}') else: raise NotImplementedError(node0) assert nodes.shape[ 0] == nnodes, f'nodes.shape={nodes.shape} nnodes={nnodes}' return nids, nodes
def test_simple_logger_log_func(self): """tests using a log function""" def log_func(typ, filename, lineno, msg): #print('typ=%r filename=%r lineno=%r msg=%r' % (typ, filename, lineno, msg)) str_to_html(typ, filename, lineno, msg) assert typ == 'INFO', '%r' % msg assert msg == 'info_log_func', '%r' % msg log = SimpleLogger(level='info', log_func=log_func) log.info('info_log_func')
def test_simple_logger(self): """tests all the logging levels""" log = SimpleLogger(level='critical') log.info('info') log.warning('warning') log.error('error') log.debug('debug') log.exception('exception') out = log.critical('critical') assert out is None
def test_enable_disable(self): """tests enabling/disabling log message""" log = SimpleLogger(level='info') log.info('info_enabled original') log.disable() log.info('info_disabled 1') log.enable() log.info('info_enabled 1') log.set_enabled(False) log.info('info_disabled 2') log.set_enabled(True) log.info('info_enabled 2')
def add_from_data_lines(cls, param_map: Dict[str, str], data_lines: List[str], log: SimpleLogger): material_name = param_map['material'] log.debug(f'material_name = {material_name}') #if len(data_lines) == 0: #pass thickness = 0. if len(data_lines) == 1: assert len(data_lines) == 1, data_lines line0 = data_lines[0] assert len(line0) == 1, data_lines thickness = float(line0[0]) #else: #aa for line in data_lines: log.info('shell - %r' % line) return ShellSection(material_name, thickness, log)
def test_tecplot_ascii_models(self): tecplot_filenames = [ 'ascii/3dgeom.dat', # good; multi-zone, geometry 'ascii/block_febrick_3d.dat', # 3d unstructured block; good #'ascii/block_fetet_3d.dat', # bad; no decimal values 'ascii/channel.dat', # 2d structured point; good #'ascii/cylinder_slice.dat', # 3d structured point; block 2 has poor formatting #'ascii/cylindrical.dat', # 3d structured empty lines; good 'ascii/ell.dat', # 2d; good 'ascii/humanoid_quad.dat', # good 'ascii/humanoid_tri.dat', # good 'ascii/movie.dat', # csv -> good 'ascii/multzn2d.dat', # 2d structured; good 'ascii/plane_slice.dat', # 2d structured multi-line; good #'ascii/point_febrick_3d_02.dat', # difficult header and funny write bug; bad 'ascii/point_fequad_2d.dat', # 2d; good 'ascii/point_fetet_3d.dat', # good 'ascii/point_fetri_2d_01.dat', # good 'ascii/point_fetri_2d_02.dat', # good 'ascii/point_fetri_2d_03.dat', # good #'ascii/simp3dbk.dat', # 3d structured block - bad 'ascii/simp3dpt.dat', # good #'ascii/simpscat.dat', # bad -> text #'ascii/simpxy.dat', # no xyz; it's a plot -> bad #'ascii/simpxy2.dat', # no xyz; it's a plot -> bad 'ascii/tiny.dat', # good ] log = SimpleLogger(level='warning', encoding='utf-8') junk_plt = os.path.join(MODEL_PATH, 'junk.plt') for fname in tecplot_filenames: tecplot_filename = os.path.join(MODEL_PATH, fname) #print(fname) log.info('read %r' % fname) model = read_tecplot(tecplot_filename, log=log) str(model) model.write_tecplot(junk_plt, res_types=None, adjust_nids=True) os.remove(junk_plt)