def write_load(xde_lists, gesfile): gesfile.write('\n') left_vara = 'load' righ_expr = ''.join(xde_lists['load']) expr_list = idx_summation(left_vara, righ_expr, xde_lists) expr_list = split_bracket_expr(expr_list[0]) for strs in expr_list: if strs == 'load=': gesfile.write(strs) else: gesfile.write(strs + '\n') # end write_load()
def check_weak(xde_lists, list_addr, weak): if xde_lists[weak][0].lower() == 'null': return elif xde_lists[weak][0].lower() == 'dist': for weak_strs, line_num in zip(xde_lists[weak][1:], list_addr[weak]): for weak_item in split_bracket_expr(weak_strs): weak_form = set( regx.findall(r'\[?\w+\;?\w+\]|\[\w+\;?\w+\]?', weak_item, regx.I)) if len(weak_form) != 1: report_error('WUF01', line_num, unsuitable_form(weak_item, 'Error') \ + "one and only one '[*;*]' form in a lowest priority expression.\n") else: miss_opr = [ weak_opr for weak_opr in ['[', ';', ']'] if weak_item.find(weak_opr) == -1 ] if len(miss_opr) != 0: report_error('WUF02', line_num, unsuitable_form(weak_item, 'Error') \ + f"It miss {Empha_color}'{' '.join(miss_opr)}'.\n") weak_func_set = set(map(lambda x: x.strip(';').lstrip('[').rstrip(']'), \ regx.findall(r'\[\w+|\w+\;|\;\w+|\w+\]', weak_item, regx.I))) check_weak_items(weak_func_set, weak_item, line_num, xde_lists) elif xde_lists[weak][0] == '%1': if weak == 'stif': report_error('WUF03', list_addr[weak][0], unsuitable_form(' '.join(xde_lists[weak]), 'Error') \ + "'STIF' must be declared as paragraph, it is distributed.\n") coeff_len = len(xde_lists[weak]) - 1 if 'disp' in xde_lists and coeff_len > 1 and coeff_len < len( xde_lists['disp']): no_coeff_var = xde_lists['disp'][coeff_len:] no_mass_list = ['0' for i in range(len(no_coeff_var))] error_type = unsuitable_form(' '.join(xde_lists[weak]), 'Error') sgest_info = f"Not enough '{weak}' coefficient for 'disp' declaration at {Empha_color}{list_addr['disp']}. " \ + f"{Error_color}If '{' '.join(no_coeff_var)}' have no 'mass', it's better declared as " \ + f"{Empha_color}'{weak} {' '.join(xde_lists[weak] + no_mass_list)}'.\n" report_error('WUF04', list_addr[weak][0], error_type + sgest_info) else: report_error('WFD01', list_addr[weak][0], faultly_declared(weak, 'Error') \ + f"Wrong key word {Empha_color}'{xde_lists[weak][0][:8]}...'\n")
def write_load(xde_lists, gesfile): gesfile.write('\n') left_vara = 'load' righ_expr = ''.join(xde_lists['load']) expr_list = idx_summation(left_vara, righ_expr, xde_lists) expr_list = split_bracket_expr(expr_list[0]) gesfile.write(expr_list[0]) for strs in expr_list[1:]: if 'cmplx_tag' in xde_lists and xde_lists['cmplx_tag'] == 1: weak_item = regx.search(r'\[\w+\]', strs, regx.I) cplx_item = regx.search(r'\(?\|[+-]?\w+\;[+-]?\w+\|\)?', strs, regx.I) if weak_item != None: weak_item = weak_item.group() if cplx_item != None: cplx_item = cplx_item.group() weak_var = weak_item.lstrip('[').rstrip(']') cplx_real_var, cplx_imag_var = cplx_item.lstrip('(').rstrip( ')').strip('|').split(';') weak_list = [weak_var + 'r', weak_var + 'i'] cplx_list = [cplx_real_var, cplx_imag_var] for i in range(2): if regx.match(r'[+-]?0(?:\.0*)?|[+-]?\.0+', cplx_list[i] ,regx.I) != None \ and cplx_list[i][-1] == '0' : continue gesfile.write(strs.replace(weak_item, f'[{weak_list[i]}]') \ .replace(cplx_item, f'({cplx_list[i]})')+'\n') else: gesfile.write(strs + '\n') # end write_load()
def check_load(xde_lists, list_addr): if not xde_lists['load'][0].isnumeric(): for weak_strs, line_num in zip(xde_lists['load'], list_addr['load']): for weak_item in split_bracket_expr(weak_strs): weak_form = regx.findall(r'\[\w+\]?|\[?\w+\]', weak_item, regx.I) if len(set(weak_form)) != 1: report_error('WUF05', line_num, unsuitable_form(weak_item, 'Error') \ + "one and only one '[*]' form in a lowest priority expression.\n") else: miss_opr = [ weak_opr for weak_opr in ['[', ']'] if weak_item.find(weak_opr) == -1 ] if len(miss_opr) != 0: report_error('WUF06', line_num, unsuitable_form(weak_item, 'Error') \ + f"It miss {Empha_color}'{' '.join(miss_opr)}'.\n") weak_func_set = set( map(lambda x: x.lstrip('[').rstrip(']'), weak_form)) check_weak_items(weak_func_set, weak_item, line_num, xde_lists)
def write_weak(weak, code_use_dict, xde_lists, gesfile): if xde_lists[weak][0].lower() != 'null' or weak in code_use_dict: gesfile.write('\n{}\n'.format(weak)) else: return if weak in code_use_dict: for strs in code_use_dict[weak]: gesfile.write(strs) if xde_lists[weak][0] == 'dist': left_vara = xde_lists[weak][0] righ_expr = '' for ii in range(1, len(xde_lists[weak])): righ_expr += xde_lists[weak][ii] expr_list = idx_summation(left_vara, righ_expr, xde_lists) expr_list = split_bracket_expr(expr_list[0]) for strs in expr_list: if strs == 'dist=': gesfile.write(strs) else: gesfile.write(strs + '\n') elif xde_lists[weak][0] == 'lump': if len(xde_lists[weak]) == 1: xde_lists[weak].append('1.0') lump_expr = {} if len(xde_lists[weak]) == 2: pass gesfile.write('lump =\n') for shaps in xde_lists['shap']: nodn = regx.search(r'\d+', shaps, regx.I).group() for vara in xde_lists['shap'][shaps]: for ii in range(int(nodn)): gesfile.write('+[{}]{}{}\n' \ .format(xde_lists[weak][1], vara, ii+1))
def parse_weak(weak, xde_dict, ges_dict): if xde_dict[weak][0].lower() != 'null' \ or weak in ges_dict['code']: ges_dict[weak] = [] else: return if xde_dict[weak][0] == 'dist': left_vara = xde_dict[weak][0] righ_expr = '' for weak_strs in xde_dict[weak][1:]: righ_expr += weak_strs expr_list = idx_summation(left_vara, righ_expr, xde_dict) expr_list = split_bracket_expr(expr_list[0]) ges_dict[weak].append(expr_list[0].replace('=', '')) for strs in expr_list[1:]: if 'cmplx_tag' in xde_dict and xde_dict['cmplx_tag'] == 1: weak_item = re.search(r'\[\w+\;\w+\]', strs, re.I) cplx_item = re.search(r'\(?\|[+-]?\w+\;[+-]?\w+\|\)?', strs, re.I) if weak_item != None: weak_item = weak_item.group() if cplx_item != None: cplx_item = cplx_item.group() weak_left_var, weak_righ_var = weak_item.lstrip('[').rstrip( ']').split(';') cplx_real_var, cplx_imag_var = cplx_item.lstrip('(').rstrip( ')').strip('|').split(';') weak_left_list = [ weak_left_var + 'r', weak_left_var + 'i', weak_left_var + 'r', weak_left_var + 'i' ] weak_righ_list = [ weak_righ_var + 'r', weak_righ_var + 'i', weak_righ_var + 'i', weak_righ_var + 'r' ] cplx_list = [ cplx_real_var, cplx_real_var, cplx_imag_var, cplx_imag_var ] if cplx_list[2][0] == '+': cplx_list[2] = cplx_list[2].replace('+', '-') elif cplx_list[2][0] == '-': cplx_list[2] = cplx_list[2].replace('-', '+') else: cplx_list[2] = '-' + cplx_list[2] for i in range(4): if re.match(r'[+-]?0(?:\.0*)?|[+-]?\.0+', cplx_list[i] ,re.I) != None \ and cplx_list[i][-1] == '0' : continue ges_dict[weak].append(strs.replace(weak_item, f'[{weak_left_list[i]};{weak_righ_list[i]}]') \ .replace(cplx_item, f'({cplx_list[i]})') ) else: ges_dict[weak].append(strs) elif xde_dict[weak][0] == 'lump': if len(xde_dict[weak]) == 1: xde_dict[weak].append('1.0') if len(xde_dict[weak]) == 2: pass ges_dict[weak].append('lump') for shaps in xde_dict['shap']: nodn = re.search(r'\d+', shaps, re.I).group() for vara in xde_dict['shap'][shaps]: for ii in range(int(nodn)): ges_dict[weak].append( f'+[{xde_dict[weak][1]}]{vara}{ii+1}')
def xde2ges(gesname, coor_type, xde_lists, list_addr, gesfile): # 0 prepare ges_shap_type = regx.search(r'[ltqwc][1-9]+', gesname, regx.I).group() ges_gaus_type = regx.search(r'g[1-9]+', gesname, regx.I) if ges_gaus_type != None: ges_gaus_type = ges_gaus_type.group() dim = regx.search(r'[1-9]+', coor_type, regx.I).group() axi = coor_type.split('d')[1] ges_shap_nodn = regx.search(r'[1-9]+', ges_shap_type, regx.I).group() ges_shap_form = ges_shap_type[0] pfelacpath = os.environ['pfelacpath'] code_use_dict = {} # use to deal with @L, @A, vol, singular, ... for code_key in ['BFmate', 'AFmate', 'func', 'stif', 'mass', 'damp']: if code_key in xde_lists['code']: code_use_dict[code_key] = [] release_code(xde_lists, code_key, pfelacpath, code_use_dict) gesfile.write(gesname + '\ndefi\n') base_shap_type = list(xde_lists['shap'].keys())[0] base_shap_nodn = regx.search(r'[1-9]+', base_shap_type, regx.I).group() base_shap_form = base_shap_type[0] # 1 write disp and var declare if 'disp' in xde_lists: # 1.1 write disp declare gesfile.write('disp ') for strs in xde_lists['disp']: gesfile.write(strs + ',') gesfile.write('\n') # 1.2 parsing var var_dict = {} for shap in xde_lists['shap'].keys(): nodn = int(regx.search(r'[1-9]+', shap, regx.I).group()) for var in xde_lists['shap'][shap]: var_dict[var] = [var + str(ii + 1) for ii in range(nodn)] # 1.3 write var declare i = 0 gesfile.write('var') for nodi in range(int(base_shap_nodn)): for strs in xde_lists['disp']: if nodi >= len(var_dict[strs]): continue gesfile.write(' ' + var_dict[strs][nodi]) i += 1 if i == 10: gesfile.write('\nvar') i = 0 gesfile.write('\n') # 2 write refc, coor and coef declare if 'coor' in xde_lists: gesfile.write('refc ') for strs in xde_lists['coor']: gesfile.write('r' + strs + ',') gesfile.write('\ncoor ') for strs in xde_lists['coor']: gesfile.write(strs + ',') gesfile.write('\n') if 'coef' in xde_lists: gesfile.write('coef ') for strs in xde_lists['coef']: gesfile.write(strs + ',') gesfile.write('\n') # 3 write func declare if 'func' in xde_lists: gesfile.write('func = ') for strs in xde_lists['func']: gesfile.write(strs + ',') gesfile.write('\n') # 4 write dord and node declare if 'disp' in xde_lists: gesfile.write('dord ') for strs in xde_lists['disp']: gesfile.write('1' + ',') gesfile.write('\n') gesfile.write('node ' + str(base_shap_nodn) + '\n') # 5 write code before mate declaration if 'BFmate' in code_use_dict: for strs in code_use_dict['BFmate']: gesfile.write(strs) # 6 write mate line if 'mate' in xde_lists: gesfile.write('mate') for var in xde_lists['mate']['default'].keys(): gesfile.write(' ' + var) for var in xde_lists['mate']['default'].keys(): gesfile.write(' ' + xde_lists['mate']['default'][var]) gesfile.write('\n') # 7 write code after mate declaration if 'AFmate' in code_use_dict: for strs in code_use_dict['AFmate']: gesfile.write(strs) # 8 write 'singular' operator declaration if 'singular' in xde_lists: gesfile.write(xde_lists['singular']) # 9 write shap and tran paragraph if 'shap' in xde_lists: gesfile.write('\nshap\n') geslib_coor = ['x', 'y', 'z'] base_shap_strs = '' # 9.1 write shap for shap in xde_lists['shap'].keys(): shap_func = 'd' + dim + shap + '.sub' path_shap = pfelacpath + 'ges/ges.lib' file_shap = open(path_shap, mode='r') shap_find, shap_strs = 0, '' # 9.1.1 find shap function in ges.lib for line in file_shap.readlines(): shap_start_file = regx.search('sub ' + shap_func, line, regx.I) shap_end_file = regx.search('end ' + shap_func, line, regx.I) if shap_start_file != None: shap_find = 1 continue if shap_end_file != None: shap_find = 0 continue if shap_find == 1: shap_strs += line file_shap.close() # note: save the base shap function for mix element when write tran if shap == base_shap_type: base_shap_strs = shap_strs # 9.1.2 replace shap func's coor by xde's coor for coor_i, coor_str in enumerate(xde_lists['coor']): shap_strs = shap_strs.replace(geslib_coor[coor_i], 'r' + coor_str) # 9.1.3 replace shap func's disp by xde's disp and write for shap_var in xde_lists['shap'][shap]: temp_strs = shap_strs.replace('u', shap_var) gesfile.write(shap_var + '=\n') gesfile.write(temp_strs) gesfile.write('\n') # 9.2 write tran gesfile.write('tran\n') shap_expr_list = base_shap_strs.split('\n') shap_expr_list.remove('') tran_expr_list = [] # 9.2.1 add '()' for shap_expr in shap_expr_list: shap_var, shap_exp = shap_expr.split('=')[:2] shap_num = regx.search(r'[0-9]+', shap_var, regx.I).group() shap_var = shap_var.replace(shap_num, '(' + shap_num + ')') tran_expr_list.append(shap_var + '=' + shap_exp) # 9.2.2 replace shap func's coor by xde's coor for coor_i, coor_str in enumerate(xde_lists['coor']): for ii in range(len(tran_expr_list)): tran_expr_list[ii] = \ tran_expr_list[ii].replace(geslib_coor[coor_i],'r'+coor_str) # 9.2.3 replace shap func's disp by by xde's coor and write for coor_str in xde_lists['coor']: gesfile.write(coor_str + '=\n') for tran_expr in tran_expr_list: gesfile.write(tran_expr.replace('u', coor_str) + '\n') gesfile.write('\n') # 9.3 write coef shap if 'coef_shap' in xde_lists: gesfile.write('coef\n') for shap in xde_lists['coef_shap'].keys(): shap_func = 'd' + dim + shap + '.sub' path_shap = pfelacpath + 'ges/ges.lib' file_shap = open(path_shap, mode='r') shap_find, shap_strs = 0, '' # 9.3.1 find shap function in ges.lib for line in file_shap.readlines(): shap_start_file = regx.search('sub ' + shap_func, line, regx.I) shap_end_file = regx.search('end ' + shap_func, line, regx.I) if shap_start_file != None: shap_find = 1 continue if shap_end_file != None: shap_find = 0 continue if shap_find == 1: shap_strs += line file_shap.close() # 9.2.1 add '()' shap_expr_list = shap_strs.split('\n') shap_expr_list.remove('') coef_expr_list = [] for shap_expr in shap_expr_list: shap_var, shap_exp = shap_expr.split('=')[:2] shap_num = regx.search(r'[0-9]+', shap_var, regx.I).group() shap_var = shap_var.replace(shap_num, '(' + shap_num + ')') coef_expr_list.append(shap_var + '=' + shap_exp) shap_strs = '\n'.join(coef_expr_list) + '\n' # 9.3.2 replace shap func's coor by xde's coor for coor_i, coor_str in enumerate(xde_lists['coor']): shap_strs = shap_strs.replace(geslib_coor[coor_i], 'r' + coor_str) # 9.3.3 replace shap func's disp by xde's disp and write for shap_var in xde_lists['coef_shap'][shap]: temp_string = shap_strs.replace('u', shap_var) gesfile.write(shap_var + '=\n') gesfile.write(temp_string) gesfile.write('\n') # 9 write gaus paragraph if 'gaus' in xde_lists: # 9.1 Gaussian integral if xde_lists['gaus'][0] == 'g': gaus_degree = regx.search(r'[0-9]+', xde_lists['gaus'], regx.I).group() # 9.1.1 line square or cube shap if ges_shap_type[0].lower() in ['l', 'q', 'c']: path_gaus = pfelacpath + 'ges/gaus.pnt' file_gaus = open(path_gaus, mode='r') gaus_find, gaus_axis, gaus_weit = 0, [], [] # 9.1.1.1 read gaus axis and weight in gaus.pnt for line in file_gaus.readlines(): gaus_start_file = regx.search('n=' + gaus_degree, line, regx.I) if gaus_start_file != None: gaus_find = 1 continue if gaus_find == 1 and line == '\n': gaus_find = 0 continue if gaus_find == 1: gaus_strs = line.split() if gaus_strs[0][0] not in ['-', '+']: gaus_strs[0] = ' ' + gaus_strs[0] gaus_axis.append(gaus_strs[0]) gaus_weit.append(gaus_strs[1]) file_gaus.close() # 9.1.1.2 write line square or cube's gaussian integra gesfile.write('gaus = ' + str(len(gaus_weit)**int(dim)) + '\n') if ges_shap_type[0].lower() == 'l': for axis_i in range(len(gaus_axis)): gesfile.write(gaus_axis[axis_i]+' ' \ +gaus_weit[axis_i]+'\n') elif ges_shap_type[0].lower() == 'q': for axis_i in range(len(gaus_axis)): for axis_j in range(len(gaus_axis)): weight = float(gaus_weit[axis_i]) \ *float(gaus_weit[axis_j]) gesfile.write (gaus_axis[axis_i]+' ' \ +gaus_axis[axis_j]+' ' \ +str(weight)+'\n') elif ges_shap_type[0].lower() == 'c': for axis_i in range(len(gaus_axis)): for axis_j in range(len(gaus_axis)): for axis_k in range(len(gaus_axis)): weight = float(gaus_weit[axis_i]) \ *float(gaus_weit[axis_j]) \ *float(gaus_weit[axis_k]) gesfile.write (gaus_axis[axis_i]+' ' \ +gaus_axis[axis_j]+' ' \ +gaus_axis[axis_k]+' ' \ +str(weight)+'\n') # 9.1.2 triangle shap elif ges_shap_type[0].lower() == 't': path_gaus = pfelacpath + 'ges/gaust.pnt' file_gaus = open(path_gaus, mode='r') gaus_find, gaus_strs = 0, '' # 9.1.2.1 tackle the gaussian degree if gaus_degree == '6': gaus_degree = '5' elif int(gaus_degree) > 12 and int(gaus_degree) < 17: gaus_degree = '12' elif int(gaus_degree) > 17: gaus_degree = '17' # 9.1.2.2 read gaus axis and weight in gaust.pnt and write for line in file_gaus.readlines(): gaus_start_file = regx.search('P' + gaus_degree, line, regx.I) if gaus_start_file != None: gaus_find = 1 continue if gaus_find == 1 and line == '\n': gaus_find = 0 continue if gaus_find == 1: gaus_strs += line file_gaus.close() gesfile.write(gaus_strs) # 9.1.3 tetrahedron shap elif ges_shap_type[0].lower() == 'w': path_gaus = pfelacpath + 'ges/gausw.pnt' file_gaus = open(path_gaus, mode='r') gaus_find, gaus_strs = 0, '' # 9.1.3.1 tackle the gaussian degree if gaus_degree == '4': gaus_degree = '3' elif gaus_degree == '6': gaus_degree = '5' elif int(gaus_degree) > 7: gaus_degree = '7' # 9.1.2.2 read gaus axis and weight in gausw.pnt and write for line in file_gaus.readlines(): gaus_start_file = regx.search('P' + gaus_degree, line, regx.I) if gaus_start_file != None: gaus_find = 1 continue if gaus_find == 1 and line == '\n': gaus_find = 0 continue if gaus_find == 1: gaus_strs += line file_gaus.close() gesfile.write(gaus_strs) else: pass # 9.2 node integral else: path_gaus = pfelacpath + 'ges/ges.lib' file_gaus = open(path_gaus, mode='r') gaus_find, gaus_strs = 0, '' # 9.2.1 read gaus axis and weight in ges.lib and write for line in file_gaus.readlines(): gaus_name = ' d' + dim + xde_lists['gaus'] + '.gau' gaus_start_file = regx.search('sub' + gaus_name, line, regx.I) gaus_end_file = regx.search('end' + gaus_name, line, regx.I) if gaus_start_file != None: gaus_find = 1 continue if gaus_end_file != None: gaus_find = 0 continue if gaus_find == 1: gaus_strs += line file_gaus.close() gesfile.write(gaus_strs) # 10 write func paragraph if 'func' in code_use_dict \ or 'vol' in xde_lists : gesfile.write('\nfunc\n') if 'vol' in xde_lists: gesfile.write(xde_lists['vol']) if 'func' in code_use_dict: for strs in code_use_dict['func']: #gesfile.write(strs) if strs[0] == '$': gesfile.write(strs) else: if strs.find('(') != -1: strs = strs.rstrip('\n') driv_list = set( regx.findall(r'\[[a-z][a-z0-9]*/[xyzros]\]', strs, regx.I)) rplc_list = [ 'driv' + str(i) for i in range(len(driv_list)) ] for rplc, driv in zip(rplc_list, driv_list): strs = strs.replace(driv, rplc) expr_objt = expr(strs.split('=')[1]) expr_strs = expr_objt.bracket_expand( expr_objt.expr_head) for rplc, driv in zip(rplc_list, driv_list): expr_strs = expr_strs.replace(rplc, driv) strs = strs.split('=')[0] + '=' + expr_strs + '\n\n' gesfile.write(strs) else: gesfile.write(strs) # 11 write stif, mass, damp paragraph for weak in ['stif', 'mass', 'damp']: if weak in xde_lists: gesfile.write('\n{}\n'.format(weak)) if weak in code_use_dict: for strs in code_use_dict[weak]: gesfile.write(strs) if xde_lists[weak][0] == 'dist': left_vara = xde_lists[weak][0] righ_expr = '' for ii in range(1, len(xde_lists[weak])): righ_expr += xde_lists[weak][ii] expr_list = idx_summation(left_vara, righ_expr, xde_lists) expr_list = split_bracket_expr(expr_list[0]) for strs in expr_list: if strs == 'dist=': gesfile.write(strs) else: gesfile.write(strs + '\n') elif xde_lists[weak][0] == 'lump': if len(xde_lists[weak]) == 1: xde_lists[weak].append('1.0') gesfile.write('lump =\n') for shaps in xde_lists['shap']: nodn = regx.search(r'\d+', shaps, regx.I).group() for vara in xde_lists['shap'][shaps]: for ii in range(int(nodn)): gesfile.write('+[{}]{}{}\n' \ .format(xde_lists[weak][1], vara, ii+1)) # 14 write load paragraph gesfile.write('\n') if 'load' in xde_lists: left_vara = 'load' righ_expr = ''.join(xde_lists['load']) expr_list = idx_summation(left_vara, righ_expr, xde_lists) expr_list = split_bracket_expr(expr_list[0]) for strs in expr_list: if strs == 'load=': gesfile.write(strs) else: gesfile.write(strs + '\n') else: print('error: no load declared') gesfile.write('\nend') gesfile.close() return False
def dist_weak(weaktype, xde_dict, file): file.write('\\[\n') write_line = '' expr_list = [] for ii in range(1,len(xde_dict[weaktype])): expr_list += split_bracket_expr(xde_dict[weaktype][ii]) for weak_strs in expr_list: def tran_index(matched): index_str = matched.group('index') index_list = index_str.split('_') index_str = '_{' for jj in range(0,len(index_list)): index_str += index_list[jj] index_str+='}' return index_str weak_strs = re.sub(r'(?P<index>(_[a-z])+)',tran_index,weak_strs) weak_list = [] second_opr = '' first_opr = '' factor = '' if weak_strs[0] != '[': first_opr = weak_strs[0] else: first_opr = '+' weak_strs = weak_strs.split('[')[1] weak_list = weak_strs.split(';') if weaktype == 'mass': if 'damp' in xde_dict: left = '\\frac{\\partial^2 '+ weak_list[0] + '}{\\partial t^2}' else: left = '\\frac{\\partial ' + weak_list[0] + '}{\\partial t}' elif weaktype == 'damp': left = '\\frac{\\partial ' + weak_list[0] + '}{\\partial t}' elif weaktype == 'stif': left = weak_list[0] weak_strs = weak_list[1] weak_list = weak_strs.split(']') righ = weak_list[0] weak_strs = weak_list[1] if weak_strs == '': factor = '' else: if weak_strs[0] == '/': second_opr = '/' factor = weak_strs.lstrip(weak_strs[0]) if second_opr == '/': factor = '1/'+factor write_line += ' \\int_{\Omega} ' write_line += factor.rstrip('+').replace('*','\cdot ')+'\cdot ' write_line += left write_line += '\delta '+righ write_line += '+' write_line = write_line.rstrip('+') file.write(write_line) file.write('\n\\]\n')