abaqus Python实例-操作excel文件.doc_第1页
abaqus Python实例-操作excel文件.doc_第2页
abaqus Python实例-操作excel文件.doc_第3页
abaqus Python实例-操作excel文件.doc_第4页
abaqus Python实例-操作excel文件.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

abaqus Python实例操作excel文件目前处理数据离不开excel,所以pythoner必须学会用python操作excel表格。Python与excel交互方法也比较多,我一开始就接触的xlrd/xlwt包。直到现在也没有发现什么bug或者缺点,而且上次从ujs505那里知道Win32Com的方法在64bit系统下无效了,但是xlrd/xlwt方法依然好用,我欣喜万分。这里给出我一个从材料单轴拉伸数据TRA文件中处理得到拉伸过程中各种应力应变量并记录到excel中的例子,其实这个例子比较乱,但是实在没有时间给弄个明了的版本了。大家将就看看from math import *import sysimport reimport xlrdfrom xlwt import Workbookbook=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=0for i in range(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=s12little=name-2:s2=re.sub(|t|;|n, ,s2)s2=re.split( +,s2)times=s22print name+run+str(times)bk=xlrd.open_workbook(Static report.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-2s0=re.sub(;, ,s0)s0=re.split( +,s0)f.seek(0)s1=f.readline()s2=f.readline()s3=f.readline()s4=f.readline()while state:s=f.readline()s=re.sub(;, ,s)s=re.split( +,s)#print s#print s0if (s=EOF)|(s=s0):state=Falseelse:force=float(s1)eee=float(s0)/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 refer to+simu_namesimu_f=open(simu_name,r)simu_state=Trues0=simu_f.readlines()s0=s0-1s0=re.sub(;, ,s0)s0=re.split( +,s0)#print s0simu_f.seek(0)simu_s1=simu_f.readline()while simu_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:#print simu_s2s_force=float(simu_s25)s_eee=float(simu_s22)s_triax=float(simu_s23)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)for i in range(len(engineer_strain):sheet.write(nrows,nclown,engineer_straini)sheet.write(nrows,nclown+1,engineer_stressi)sheet.write(nrows,nclown+2,true_straini)sheet.write(nrows,nclown+3,true_stressi)sheet.write(nrows,nclown+4,plastic_straini)nrows+=1nclown+=5#output engineer strain and stressnrows=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)for i in range(len(engineer_strain):sheet1.write(nrows,nclown_e,engineer_straini)sheet1.write(nrows,nclown_e+1,engineer_stressi)nrows+=1nclown_e+=4#output true strain and stressnrows=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)for i in range(len(engineer_strain):sheet2.write(nrows,nclown_t,true_straini)sheet2.write(nrows,nclown_t+1,true_stressi)nrows+=1nclown_t+=4#output plastic strain and stressnrows=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)for i in range(len(engineer_strain):sheet3.write(nrows,nclown_p,plastic_straini)sheet3.write(nrows,nclown_p+1,true_stressi)nrows+=1nclown_p+=4#output modified plastic strain and true stressnrows=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_pm,sample)sheet4.write(1,nclown_pm+1,name)sheet4.write(1,nclown_pm+2,run)sheet4.write(1,nclown_pm+3,times)sheet4.write(2,nclown_pm,PL_strain)sheet4.write(2,nclown_pm+1,Force)running=Truefor i in range(len(engineer_strain):if running:mincr=150temp_e=(test_forcei-test_forcei+mincr)/(plastic_straini-plastic_straini+mincr)if temp_e400000.0:i_temp=irunning=Falseelse:modifed_strain=engineer_straini-engineer_straini_tempmodifed_plastic_strain=log(1.0+modifed_strain)-engineer_stressi*(1.0+modifed_strain)/E_modulussheet4.write(nrows,nclown_pm,modifed_plastic_strain)sheet4.write(nrows,nclown_pm+1,test_forcei)nrows+=1#output simulation resultnrows=3sheet4.write(2,nclown_pm+2,PL_strain)sheet4.write(2,nclown_pm+3,Force)sheet4.write(2,nclown_pm+4,TRIAX)for j in range(len(simu_P_strain):sheet4.write(nrows,nclown_pm+2,simu_P_strainj)sheet4.write(nrows,nclown_pm+3,simu_forcej)sheet4.write(nrows,nclown_pm+4,simu_triaxj)nrows+=1#next file(Test result)nclown_pm+=5book.save(material_treat.xls)另一例子import csvfrom odbAccess import *from abaqusConstants import *filename=getInput(Please input the ODB file name)#下面这样都是我定义的字典或list,用来存保存提取数据的elementArea= elementConn=nodeArea =timeTP =#下面可以看做一般的从odb文件中提取结果的步骤#打开指定的odb文件odb=openOdb(path=filename)#得到assembly中所有的instanceinst=odb.rootAssembly.instances #或取第一个instance中的所有单元,因为我这个odb里面只有一个instance#.keys()方法可以获得一个list有所有的instance名字elments=instinst.keys()0.elements#下面一段对单元循环,得到每个单元的几个结点,然后记录下来for el in elments: label=el.label nodes=el.connectivity elementConnlabel=nodes#节点nodes=instinst.keys()0.nodesfor nd in nodes: label=nd.label nodeArealabel=0#打开

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论