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 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 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 _cast_matrix_matpool(table_name: str, real_imag_array, col_nids_array, col_dofs_array, row_nids_array, row_dofs_array, matrix_shape: Tuple[int, int], dtype: str, is_symmetric: bool, log: SimpleLogger, apply_symmetry: bool = False) -> Matrix: """helper method for _read_matpool_matrix""" #op2 = self.op2 make_matrix_symmetric = apply_symmetry and matrix_shape == 'symmetric' # TODO: this is way slower than it should be # because we didn't preallocate the data and the # grids_comp_array_to_index function needs work grids1 = col_nids_array comps1 = col_dofs_array grids2 = row_nids_array comps2 = row_dofs_array assert len(grids1) == len(comps1), 'ngrids1=%s ncomps1=%s' % (len(grids1), len(comps1)) assert len(grids1) == len(grids2), 'ngrids1=%s ngrids2=%s' % (len(grids1), len(grids2)) assert len(comps1) == len(comps2), 'ncomps1=%s ncomps2=%s' % (len(comps1), len(comps2)) j1, j2, nj1, nj2, nj = grids_comp_array_to_index(grids1, comps1, grids2, comps2, make_matrix_symmetric, idtype='int32') assert len(j1) == len(j2), 'nj1=%s nj2=%s' % (len(j1), len(j2)) assert len(grids1) == len(real_imag_array), 'ngrids1=%s nreals=%s' % ( len(j1), len(real_imag_array)) # not 100% on these, they might be flipped #ncols = len(np.unique(j1)) #mrows = len(np.unique(j2)) if is_symmetric and make_matrix_symmetric: mrows = nj ncols = nj #print(' j1 =', j1) #print(' j2 =', j2) else: ncols = nj1 mrows = nj2 # C:\MSC.Software\simcenter_nastran_2019.2\tpl_post2\tr1071x.op2 #print(real_imag_array) #print(j1) #print(j2) #print(mrows, ncols) try: matrix = scipy.sparse.coo_matrix((real_imag_array, (j2, j1)), shape=(mrows, ncols), dtype=dtype) except ValueError: print('gc1', grids1, comps1) print('gc2', grids2, comps2) print(f'j1={j1}') print(f'j2={j2}') print(f'shape=({mrows}, {ncols})') msg = 'Passed all the checks; cannot build MATPOOL sparse matrix...\n' spaces = ' ' msg += '%sname=%s dtype=%s nrows=%s ncols=%s nj1=%s nj2=%s nj=%s' % ( spaces, table_name, dtype, mrows, ncols, nj1, nj2, nj) log.error(msg) raise # enforce symmetry if necessary if make_matrix_symmetric: # get the upper and lower triangular matrices upper_tri = scipy.sparse.triu(matrix) lower_tri = scipy.sparse.tril(matrix) # extracts a [1, 2, 3, ..., n] off the diagonal of the matrix # and make it a diagonal matrix diagi = scipy.sparse.diags(scipy.sparse.diagional(upper_tri)) # Check to see which triangle is populated. # If they both are, make sure they're equal # or average them and throw a warning lnnz = (lower_tri - diagi).nnz unnz = (upper_tri - diagi).nnz assert isinstance(lnnz, int), type(lnnz) assert isinstance(unnz, int), type(unnz) # both upper and lower triangle are populated if lnnz > 0 and unnz > 0: upper_tri_t = upper_tri.T if lower_tri == upper_tri_t: matrix = upper_tri + upper_tri_t - diagi else: log.warning( f'Matrix {table_name!r} marked as symmetric does not contain ' 'symmetric data. Data will be symmetrized by averaging.') matrix = (matrix + matrix.T) / 2. elif lnnz > 0: # lower triangle is populated matrix = lower_tri + lower_tri.T - diagi elif unnz > 0: # upper triangle is populated matrix = upper_tri + upper_tri_t - diagi else: # matrix is diagonal (or null) matrix = diagi data = matrix # matrix is symmetric, but is not stored as symmetric matrix_shape = 'rectangular' m = Matrix(table_name, is_matpool=True, form=matrix_shape) m.data = matrix m.col_nid = col_nids_array m.col_dof = col_dofs_array m.row_nid = row_nids_array m.row_dof = row_dofs_array m.form = matrix_shape #print(m) log.debug(m) return m