def getPressAve(odbname):
odb=openOdb(odbname)
lastFrame=odb.steps['Step-1'].frames[-1]
pressure=lastFrame.fieldOutputs['CPRESS']
press=[[0,0]] # sets the first element to [0,0]
for n in pressure.values:
gridPt=part1.nodes.getFromLabel(n.nodeLabel)
coord=assemb.getCoordinates(gridPt)
press.append([n.nodeLabel,n.data,coord])
press=avePress=press[1:] # removes the first element
press.sort(Comp_X)
print ('pressure extracted')
index=0
while index<len(press):
sum=0
tally=0
if index!=0:
sum=sum+press[index-1][1]
tally=tally+1
if index!=1:
sum=sum+press[index-2][1]
tally=tally+1
if index!=2:
sum=sum+press[index][1]
tally=tally+1
if index<len(press)-1:
sum=sum+press[index+1][1]
tally=tally+1
if index<len(press)-2:
sum=sum+press[index+2][1]
tally=tally+1
average=sum/tally
avePress[index][1]=average
index=index+1
odb.close()
print ('pressure averaged')
return avePress
Tags:
您忘记正确缩进代码:
正如您的一样,
return
关键字在函数之外,因此出现了错误:SyntaxError: 'return' outside function
。你知道吗在Python中,缩进很重要。实际上,您正在定义一个名为
getPressAve
的函数,它只执行以下操作:定义完函数后,继续执行
而这样的在函数之外。那不是你想要的。解决方案是将
odb=openOdb(odbname)
行之后的所有内容缩进到该级别,因此这些行被解释为函数体的一部分。你知道吗相关问题 更多 >
编程相关推荐