我已经在python中编写了一个脚本来对Abaqus中的一组文件进行后处理。该脚本按顺序打开abaqus输出数据库文件,读取多个节点的结果,将这些结果写入.txt文件中,然后关闭odbs(输出数据库。开始时该过程非常迅速。几次打开和关闭后文件(例如50次之后)的过程变得更加缓慢,最后(可能由于缺少命令),程序(Abaqus)崩溃了。
我添加了gc.collect命令,并以某种方式提供了帮助,但问题仍然存在。
我还注意到,尽管写入的文件位于另一张光盘(D)中,但在光盘C:的过程中空间仍被占用。重新启动计算机后,该空间已可用。
有谁知道它为什么会发生,我该如何解决?我的意思是我该如何避免内存变满和过程变慢。这是我的脚本:
from abaqus import *
from abaqusConstants import *
from caeModules import *
from driverUtils import executeOnCaeStartup
import gc
executeOnCaeStartup()
session.viewports['Viewport: 1'].partDisplay.geometryOptions.setValues(
referenceRepresentation=ON)
nodes = [1001,1201,1401,1601,1801,2001,2201,2401,2601,2801,3001]
a = ["5"]
Kx = ["0001", "001","1"]
dth = ["0", "05" , "1" ,"5", "10"]
dw = ["0","1","5" ,"10" ,"40"]
fmt = "WD_dw{w}_dth{y}_Kx{z}_a{x}"
k = 0
j = 0
for x in a:
j = j + 1
print 'j =',j
f = open("WD_sin_results_{j}.txt".format(j=j), 'w')
for z in Kx:
for y in dth:
for w in dw:
f.write("\n" + fmt.format(w=w, z=z, y=y, x=x)+ "\n")
lista = []
listb = []
listc = []
xy1 = []
k = k + 1
print 'k =',k
o1 = session.openOdb(name='E:\Abaqus\WD_sin_p1_c{k}.odb'.format(k=k))
session.viewports['Viewport: 1'].setValues(displayedObject=o1)
leaf = dgo.LeafFromOdbElementMaterials(elementMaterials=('SOIL', ))
session.viewports['Viewport: 1'].odbDisplay.displayGroup.replace(leaf=leaf)
odbName=session.viewports[session.currentViewportName].odbDisplay.name
session.odbData[odbName].setValues(activeFrames=(('Step-1', ('0:-1', )), ))
odb = session.odbs['E:\Abaqus\WD_sin_p1_c{k}.odb'.format(k=k)]
for i in nodes:
print 'i =',i
session.xyDataListFromField(odb=odb, outputPosition=NODAL, variable=(('CPRESS', ELEMENT_NODAL), ), nodeLabels=(('PART-1-1', ('%i'%(i), )), ))
xy1 = []
xy1 = session.xyDataObjects['CPRESS (Not averaged) PI: PART-1-1 N: %i'%(i)]
xy1.setValues(
sourceDescription='CPRESS (Not averaged) PI: PART-1-1 N: %i'%(i))
xy2 = xy1[530]
xy3 = xy2[1]
print 'xy3:', xy3
if xy3 < 0:
lista = currentMin(truncate(xyData=xy1, startX=5, endX=6))
lista.setValues(
sourceDescription='currentMin ( truncate ( xyData="CPRESS (Not averaged) PI: PART-1-1 N: {i}" ,startX=5, endX=6 ) )'.format(i=i))
else:
lista = currentMax(truncate(xyData=xy1, startX=5, endX=6))
lista.setValues(
sourceDescription='currentMax ( truncate ( xyData="CPRESS (Not averaged) PI: PART-1-1 N: {i}" ,startX=5, endX=6 ) )'.format(i=i))
listb = lista[100]
print "listb:", lista[100]
listc = listb[1]
print "listc:", listb[1]
f.write('%s'%listc+ "\n")
del session.xyDataObjects['CPRESS (Not averaged) PI: PART-1-1 N: %i'%(i)]
del session.xyDataObjects['CPRESS (Not averaged) PI: PART-1-1 N: %i'%(i)]
del session.xyDataObjects['_temp_1']
del session.xyDataObjects['_temp_2']
del session.xyDataObjects['_temp_3']
del session.xyDataObjects['_temp_4']
del session.xyDataObjects['_temp_5']
del session.xyDataObjects['_temp_6']
del session.xyDataObjects['_temp_7']
del session.xyDataObjects['_temp_8']
del session.xyDataObjects['_temp_9']
del session.xyDataObjects['_temp_10']
del session.xyDataObjects['_temp_11']
del session.xyDataObjects['_temp_12']
del session.xyDataObjects['_temp_13']
del session.xyDataObjects['_temp_14']
del session.xyDataObjects['_temp_15']
del session.xyDataObjects['_temp_16']
del session.xyDataObjects['_temp_17']
del session.xyDataObjects['_temp_18']
del session.xyDataObjects['_temp_19']
del session.xyDataObjects['_temp_20']
del session.xyDataObjects['_temp_21']
del session.xyDataObjects['_temp_22']
session.odbs['E:\Abaqus\WD_sin_p1_c{k}.odb'.format(k=k)].close()
gc.collect()
f.close()
最佳答案
这里有一些建议:
1-使用odbAccess在abaqus python命令提示符下打开odbs。不使用Abaqus Viewer可能会节省一些内存
2-直接从odb中的帧中提取数据。不要使用XY数据列表操作。
以下代码未经测试,但可能会给您一些想法。如果要使用它,则很可能必须对其进行调试。我不知道您要从odb提取什么数据,但我做了一个猜测。
from abaqus import *
from abaqusConstants import *
from odbAccess import *
import odbAccess
from caeModules import *
from driverUtils import executeOnCaeStartup
import numpy as np
nodeLabels = [1001,1201,1401,1601,1801,2001,2201,2401,2601,2801,3001]
instanceName='PART-1-1'
a = ["5"]
Kx = ["0001", "001","1"]
dth = ["0", "05" , "1" ,"5", "10"]
dw = ["0","1","5" ,"10" ,"40"]
fmt = "WD_dw{w}_dth{y}_Kx{z}_a{x}"
k = 0
j = 0
for x in a:
j += 1
print 'j =',j
with open("WD_sin_results_{j}.txt".format(j=j), 'w') as f:
for z in Kx:
for y in dth:
for w in dw:
f.write("\n" + fmt.format(w=w, z=z, y=y, x=x)+ "\n")
k += 1
print 'k =',k
odb = odbAccess.openOdb(name='E:\Abaqus\WD_sin_p1_c{k}.odb'.format(k=k))
step=odb.steps.values()[0] # evaluate 1st step in odb
frames=step.frames # evaluate all frames in step
inst=odb.rootAssembly.instances[instanceName]
matrix=np.zeros((len(nodeLabels),len(frames))) #initialse NumPy array, array = node x frame
for frameNum,frame in enumerate(frames):
CPRESSframe=frame.fieldOutputs['CPRESS']
for nodeNum,nodeLabel in enumerate(nodeLabels):
node=inst.getNodeFromLabel(nodeLabel)
matrix[nodeNum,frameNum]=CPRESSframe.getSubset(region=node).values[0].data
# Write out the largest absolute cpress over all the frames for each node
for nodeNum,nodeLabel in enumerate(nodeLabels):
idx=np.argmax(abs(matrix[nodeNum,:])) # find the frame with the largest absolute cpress for this node
f.write('%s'%matrix[nodeNum,idx]+ "\n")
odb.close()
关于python - 内存不足python Abaqus,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33900696/