gpt4 book ai didi

python - python Abaqus 内存不足

转载 作者:太空宇宙 更新时间:2023-11-03 17:13:07 28 4
gpt4 key购买 nike

我用 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 命令提示符打开 odb。不使用 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com