for i, filepath in enumerate( glob.glob(r'.\linear_mathematica_10x10\k*.txt')): print(filepath) with open(filepath) as f: filename = os.path.basename(filepath) names = filename[:-4].split('_') string = f.read() string = string.replace('\r', '') string = string.replace('\n', '') string = string.replace('\n', '') string = string.replace('Pi','pi') string = string.replace('Sin','sin') string = string.replace('Cos','cos') string = string.replace('{','') string = string.replace('}','') string = string.replace('^','**') string = string.replace('\\','') tmp = map(eval, string.split(',')) size = len(tmp)**0.5 print size assert size % 1 == 0 size = int(size) print('Estimated size: {0}'.format(size)) matrix = sympy.Matrix(np.atleast_2d(tmp).reshape(size, size)) printstr = mprint_as_sparse(matrix, names[0], names[1], print_file=False, collect_for=None, subs=subs, full_symmetric=True) with open('.\\linear_sparse_10x10\\' + filename, 'w') as f: f.write(printstr)
subs = { } def List(*e): return list(e) for i, filepath in enumerate( glob.glob(r'.\output_expressions_mathematica\fortran_*.txt')): print(filepath) with open(filepath) as f: filename = os.path.basename(filepath) names = filename[:-4].split('_') lines = [line.strip() for line in f.readlines()] string = ''.join(lines) string = string.replace('\\','') tmp = eval(string) matrix = sympy.Matrix(np.atleast_2d(tmp)) printstr = '' for i in range(matrix.shape[0]): for j in range(matrix.shape[1]): if matrix[i,j] == 0: continue else: printstr += '%s[row+%d, col+%d] = %s\n' % (names[1], i, j, str(matrix[i, j])) printstr = mprint_as_sparse(matrix, names[1], "11", print_file=False, collect_for=None, subs=subs) with open('.\\output_expressions_python\\' + filename, 'w') as f: f.write(printstr)
sympy.var('kphixBot, kphixTop') def List(*e): return list(e) for i, filepath in enumerate(glob.glob(r'.\linear_mathematica\fortran_*.txt')): print filepath with open(filepath) as f: filename = os.path.basename(filepath) names = filename[:-4].split('_') lines = [line.strip() for line in f.readlines()] string = ''.join(lines) string = string.replace('Pi', 'pi') string = string.replace('Sin', 'sin') string = string.replace('Cos', 'cos') string = string.replace('{', '(') string = string.replace('}', ')') string = string.replace('^', '**') string = string.replace('\\', '') tmp = eval(string) matrix = sympy.Matrix(np.atleast_2d(tmp)) printstr = mprint_as_sparse(matrix, names[2], names[3], print_file=False, collect_for=None) with open('.\\linear_sparse\\' + filename, 'w') as f: f.write(printstr)
for i, filepath in enumerate( glob.glob(r'.\output_expressions_mathematica\fortran_*.txt')): print(filepath) with open(filepath) as f: filename = os.path.basename(filepath) names = filename[:-4].split('_') lines = [line.strip() for line in f.readlines()] string = ''.join(lines) string = string.replace('\\', '') tmp = eval(string) matrix = sympy.Matrix(np.atleast_2d(tmp)) printstr = '' for i in range(matrix.shape[0]): for j in range(matrix.shape[1]): if matrix[i, j] == 0: continue else: printstr += '%s[row+%d, col+%d] = %s\n' % ( names[1], i, j, str(matrix[i, j])) printstr = mprint_as_sparse(matrix, names[1], "11", print_file=False, collect_for=None, subs=subs) with open('.\\output_expressions_python\\' + filename, 'w') as f: f.write(printstr)
sympy.var('B11, B12, B16, B22, B26, B66') sympy.var('D11, D12, D16, D22, D26, D66') sympy.var('E11, nu, h, Fc, P, T') sympy.var('kuBot, kuTop, kvBot, kvTop') sympy.var('kphixBot, kphixTop') def List(*e): return list(e) for i, filepath in enumerate( glob.glob(r'.\linear_mathematica\fortran_*.txt')): print filepath with open(filepath) as f: filename = os.path.basename(filepath) names = filename[:-4].split('_') lines = [line.strip() for line in f.readlines()] string = ''.join(lines) string = string.replace('Pi','pi') string = string.replace('Sin','sin') string = string.replace('Cos','cos') string = string.replace('{','(') string = string.replace('}',')') string = string.replace('^','**') string = string.replace('\\','') tmp = eval(string) matrix = sympy.Matrix(np.atleast_2d(tmp)) printstr = mprint_as_sparse(matrix, names[2], names[3], print_file=False, collect_for=None) with open('.\\linear_sparse\\' + filename, 'w') as f: f.write(printstr)
for i, filepath in enumerate( glob.glob(r'.\linear_mathematica_8x8\c*.txt')): print(filepath) with open(filepath) as f: filename = os.path.basename(filepath) names = filename[:-4].split('_') string = f.read() string = string.replace('\r', '') string = string.replace('\n', '') string = string.replace('\n', '') string = string.replace('Pi','pi') string = string.replace('Sin','sin') string = string.replace('Cos','cos') string = string.replace('{','') string = string.replace('}','') string = string.replace('^','**') string = string.replace('\\','') tmp = map(eval, string.split(',')) size = len(tmp)**0.5 print size assert size % 1 == 0 size = int(size) print('Estimated size: {0}'.format(size)) matrix = sympy.Matrix(np.atleast_2d(tmp).reshape(size, size)) printstr = mprint_as_sparse(matrix, names[1], names[2], print_file=False, collect_for=None, subs=subs, triu_only=True) with open('.\\linear_sparse_8x8\\' + filename, 'w') as f: f.write(printstr)
with open(filepath) as f: filename = os.path.basename(filepath) names = filename[:-4].split('_') string = f.read() string = string.replace('\r', '') string = string.replace('\n', '') string = string.replace('\n', '') string = string.replace('Pi', 'pi') string = string.replace('Sin', 'sin') string = string.replace('Cos', 'cos') string = string.replace('{', '') string = string.replace('}', '') string = string.replace('^', '**') string = string.replace('\\', '') tmp = map(eval, string.split(',')) size = len(tmp)**0.5 print size assert size % 1 == 0 size = int(size) print('Estimated size: {0}'.format(size)) matrix = sympy.Matrix(np.atleast_2d(tmp).reshape(size, size)) printstr = mprint_as_sparse(matrix, names[0], names[1], print_file=False, collect_for=None, subs=subs, full_symmetric=True) with open('.\\linear_sparse_10x10\\' + filename, 'w') as f: f.write(printstr)