phd-scripts/Biomaterials13/StudyO1/OptPostB2.py

47 lines
1.3 KiB
Python
Raw Normal View History

2024-05-13 19:50:21 +00:00
# Import Neccesary Abaqus Modules
from abaqusConstants import *
from odbAccess import *
import sys
import os
jobName=sys.argv[-2]
resFile=sys.argv[-1]
odbfilename=jobName+'.odb'
try:
odb=openOdb(path=odbfilename)
aNod=odb.rootAssembly.instances['AMESH-1'].nodeSets['E1'].nodes[0].coordinates[0]
bNod=odb.rootAssembly.instances['AMESH-1'].nodeSets['E2'].nodes[0].coordinates[0]
rlen=abs(aNod-bNod)
check=0.
try:
for eachFrame in odb.steps["Step-5"].frames:
tforce=0.
for currentForce in eachFrame.fieldOutputs["CNORMF ASSEMBLY_AOUTER/ASSEMBLY_SURF-1"].values:
fx=currentForce.data[0]
fy=currentForce.data[1]
fz=currentForce.data[2]
tforce=tforce+sqrt(fx*fx+fy*fy+fz*fz)
aSet=odb.rootAssembly.instances['OUTER-1']
uy=eachFrame.fieldOutputs["U"].getSubset(region=aSet).values[0].data[1]
uz=eachFrame.fieldOutputs["U"].getSubset(region=aSet).values[0].data[2]
rad=sqrt(uy*uy+uz*uz)
if tforce>0.:
check=check+1
if check==2:
f1=tforce
r1=rad
if check==5:
f2=tforce
r2=rad
break
stiff=abs(f2-f1)/abs(r2-r1)
except:
stiff=0.
stiff=stiff/rlen
except:
stiff=0.
outFile = open(resFile,"w")
objFn=1.-(0.15*abs(stiff))
outFile.write("%12.6f \n " % (objFn))
outFile.close()
odb.close()