abaqus Python实例-操作excel文件

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

abaqusPython实例——操作excel文件目前处理数据离不开excel,所以pythoner必须学会用python操作excel表格。Python与excel交互方法也比较多,我一开始就接触的xlrd/xlwt包。直到现在也没有发现什么bug或者缺点,而且上次从ujs505那里知道Win32Com的方法在64bit系统下无效了,但是xlrd/xlwt方法依然好用,我欣喜万分。这里给出我一个从材料单轴拉伸数据TRA文件中处理得到拉伸过程中各种应力应变量并记录到excel中的例子,其实这个例子比较乱,但是实在没有时间给弄个明了的版本了。大家将就看看frommathimport*importsysimportreimportxlrdfromxlwtimportWorkbookbook=Workbook()sheet=book.add_sheet('test_NT',cell_overwrite_ok=True)sheet1=book.add_sheet('engineer',cell_overwrite_ok=True)sheet2=book.add_sheet('True',cell_overwrite_ok=True)sheet3=book.add_sheet('Plastic',cell_overwrite_ok=True)sheet4=book.add_sheet('Plastic_modify',cell_overwrite_ok=True)total_nubmer=46nclown=0nclown_e=0nclown_t=0nclown_p=0nclown_pm=0foriinrange(total_nubmer):myfile='tensile-'+str(i+1)f=open(myfile+'.TRA','r')engineer_strain=[]true_strain=[]engineer_stress=[]true_stress=[]plastic_strain=[]test_force=[]s1=f.readline()s2=f.readline()s3=f.readline()s4=f.readline()s1=re.sub('|\t|;|\n','',s1)s1=re.split('+',s1)name=s1[2]little=name[-2:]s2=re.sub('|\t|;|\n','',s2)s2=re.split('+',s2)times=s2[2]printname+'run'+str(times)bk=xlrd.open_workbook('Staticreport.xls')sh=bk.sheet_by_name(Stat)diameter=sh.cell_value(i+2,4)area=pi*((diameter)**2)/4E_modulus=sh.cell_value(i+2,7)state=Trues0=f.readlines()s0=s0[-2]s0=re.sub(';','',s0)s0=re.split('+',s0)f.seek(0)s1=f.readline()s2=f.readline()s3=f.readline()s4=f.readline()whilestate:s=f.readline()s=re.sub(';','',s)s=re.split('+',s)#prints#prints0if(s==EOF)|(s==s0):state=Falseelse:force=float(s[1])eee=float(s[0])/100.0sss=force/areatest_force.append(force)engineer_strain.append(eee)engineer_stress.append(sss)true_strain.append(log(1.0+eee))true_stress.append(sss*(1.0+eee))plastic_strain.append(log(1.0+eee)-sss*(1.0+eee)/E_modulus)f.close()##########################################################3simu_strain=[]simu_P_strain=[]simu_triax=[]simu_force=[]simu_E=204323.0simu_little=str(int(little)+3)simu_name=New_pass+simu_little+test.datprint'referto'+simu_namesimu_f=open(simu_name,'r')simu_state=Trues0=simu_f.readlines()s0=s0[-1]s0=re.sub(';','',s0)s0=re.split('+',s0)#prints0simu_f.seek(0)simu_s1=simu_f.readline()whilesimu_state:simu_s2=simu_f.readline()simu_s2=re.sub(';','',simu_s2)simu_s2=re.split('+',simu_s2)if(simu_s2==EOF)|(simu_s2==s0):simu_state=Falseelse:#printsimu_s2s_force=float(simu_s2[5])s_eee=float(simu_s2[2])s_triax=float(simu_s2[3])s_sss=s_force/areasimu_force.append(s_force)simu_triax.append(s_triax)simu_strain.append(s_eee)simu_P_strain.append(log(1.0+s_eee)-s_sss*(1.0+s_eee)/simu_E)simu_f.close()##########################################################3nrows=3sheet.write(0,nclown,'sample')sheet.write(0,nclown+2,name)sheet.write(1,nclown,area)sheet.write(1,nclown+2,area)sheet.write(1,nclown+1,diameter)sheet.write(1,nclown+3,E_modulus)sheet.write(1,nclown+4,E_modulus)sheet.write(2,nclown,E_strain)sheet.write(2,nclown+1,E_stress)sheet.write(2,nclown+2,T_strain)sheet.write(2,nclown+3,T_stress)sheet.write(2,nclown+4,PL_strain)foriinrange(len(engineer_strain)):sheet.write(nrows,nclown,engineer_strain[i])sheet.write(nrows,nclown+1,engineer_stress[i])sheet.write(nrows,nclown+2,true_strain[i])sheet.write(nrows,nclown+3,true_stress[i])sheet.write(nrows,nclown+4,plastic_strain[i])nrows+=1nclown+=5#outputengineerstrainandstressnrows=3sheet1.write(0,nclown_e,'file')sheet1.write(0,nclown_e+1,myfile)sheet1.write(0,nclown_e+2,E_modulus)sheet1.write(0,nclown_e+3,E_modulus)sheet1.write(1,nclown_e,'sample')sheet1.write(1,nclown_e+1,name)sheet1.write(1,nclown_e+2,'run')sheet1.write(1,nclown_e+3,times)sheet1.write(2,nclown_e,E_strain)sheet1.write(2,nclown_e+1,E_stress)foriinrange(len(engineer_strain)):sheet1.write(nrows,nclown_e,engineer_strain[i])sheet1.write(nrows,nclown_e+1,engineer_stress[i])nrows+=1nclown_e+=4#outputtruestrainandstressnrows=3sheet2.write(0,nclown_t,'file')sheet2.write(0,nclown_t+1,myfile)sheet2.write(0,nclown_t+2,E_modulus)sheet2.write(0,nclown_t+3,E_modulus)sheet2.write(1,nclown_t,'sample')sheet2.write(1,nclown_t+1,name)sheet2.write(1,nclown_t+2,'run')sheet2.write(1,nclown_t+3,times)sheet2.write(2,nclown_t,T_strain)sheet2.write(2,nclown_t+1,T_stress)foriinrange(len(engineer_strain)):sheet2.write(nrows,nclown_t,true_strain[i])sheet2.write(nrows,nclown_t+1,true_stress[i])nrows+=1nclown_t+=4#outputplasticstrainandstressnrows=3sheet3.write(0,nclown_p,'file')sheet3.write(0,nclown_p+1,myfile)sheet3.write(0,nclown_p+2,E_modulus)sheet3.write(0,nclown_p+3,E_modulus)sheet3.write(1,nclown_p,'sample')sheet3.write(1,nclown_p+1,name)sheet3.write(1,nclown_p+2,'run')sheet3.write(1,nclown_p+3,times)sheet3.write(2,nclown_p,PL_strain)sheet3.write(2,nclown_p+1,T_stress)foriinrange(len(engineer_strain)):sheet3.write(nrows,nclown_p,plastic_strain[i])sheet3.write(nrows,nclown_p+1,true_stress[i])nrows+=1nclown_p+=4#outputmodifiedplasticstrainandtruestressnrows=3i_temp=1sheet4.write(0,nclown_pm,'file')sheet4.write(0,nclown_pm+1,myfile)sheet4.write(0,nclown_pm+2,E_modulus)sheet4.write(0,nclown_pm+3,E_modulus)sheet4.write(1,nclown

1 / 12
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功