phd-scripts/Biomaterials13/Sample_ParamSweep/OptB.py

126 lines
4.1 KiB
Python
Raw Normal View History

2024-05-13 19:50:21 +00:00
# Import Neccesary Abaqus Modules
from abaqusConstants import *
from abaqus import *
from odbAccess import *
import regionToolset
import sys
import os
import interaction
import mesh
#Read in Model Parameters
paramFile=sys.argv[-1]
jobName=paramFile.encode("hex")
os.system ("cp %s %s" % ('OptB.cae', jobName+'.cae'))
mdb=openMdb(jobName+'.cae')
inFile = open(paramFile,"r")
inFile.readline()
x1,name1=inFile.readline().split()
x2,name2=inFile.readline().split()
x3,name3=inFile.readline().split()
x4,name4=inFile.readline().split()
x5,name5=inFile.readline().split()
x6,name6=inFile.readline().split()
mname='Dream6'
#Generate New Model
aModel=mdb.models[mname]
aAss=aModel.rootAssembly
tol=0.0001
radius=0.75
numCrowns=6.
W=float(x1)
T=float(x2)
L1=float(x3)
L2=float(x4)*L1
L3=float(x5)
H2=float(x6)
H1=(pi*radius)/(2.*numCrowns)
# Modify Part
aPart=aModel.parts['Geom']
aSketch=aPart.features['Solid extrude-1'].sketch
aModel.ConstrainedSketch(name='__edit__', objectToCopy=aSketch)
bSketch=aModel.sketches['__edit__']
bSketch.parameters['w'].setValues(expression=str(W/2.))
bSketch.parameters['h1'].setValues(expression=str(H1))
bSketch.parameters['h2'].setValues(expression=str(H2))
bSketch.parameters['l1'].setValues(expression=str(L1))
bSketch.parameters['l2'].setValues(expression=str(L2))
bSketch.parameters['l3'].setValues(expression=str(L3))
aPart.features['Solid extrude-1'].setValues(sketch=bSketch)
del aModel.sketches['__edit__']
aPart.features['Solid extrude-1'].setValues(depth=T)
aPart.regenerate()
# Mesh Part
aPart.seedPart(size=W/6., deviationFactor=0.1)
aPart.generateMesh()
# Create Orphan Mesh
aPart.PartFromMesh(name='AMesh')
bPart=aModel.parts['AMesh']
# Create Sets,Sections,Surfaces
for nameSet,eachSet in aPart.sets.items():
bPart.Set(name=nameSet, nodes=eachSet.nodes)
bPart.Set(name='AllE', elements=aPart.sets['All'].elements)
bPart.Set(name='InnerE', elements=aPart.sets['Inner'].elements)
bPart.Set(name='OuterE', elements=aPart.sets['Outer'].elements)
region = regionToolset.Region(elements=bPart.elements)
bPart.SectionAssignment(region=region, sectionName='Magnesium')
aPart=aModel.parts['AMesh']
elemType1 = mesh.ElemType(elemCode=C3D8R, elemLibrary=STANDARD,
kinematicSplit=AVERAGE_STRAIN, secondOrderAccuracy=OFF,
hourglassControl=ENHANCED, distortionControl=DEFAULT)
pickedRegions =(aPart.elements, )
aPart.setElementType(regions=pickedRegions, elemTypes=(elemType1, ))
# Wrap Part
nlist=[]
clist=[]
for eachnode in aPart.nodes:
theta=eachnode.coordinates[1]/radius
newcoord1=eachnode.coordinates[0]
newcoord2=(radius-eachnode.coordinates[2])*cos(theta)
newcoord3=(radius-eachnode.coordinates[2])*sin(theta)
nlist.append(eachnode)
clist.append((newcoord1,newcoord2,newcoord3))
aPart.editNode(nodes=nlist,coordinates=clist)
aPart.regenerate()
aAss.regenerate()
aInst=aAss.instances['AMesh-1']
aModel.rootAssembly.Set(name='Set-1',nodes=aInst.nodes)
incFile=open('NodeData.inc','w')
numFaces=0
pstring=''
# Cycle through all element faces
for eachFace in aPart.elementFaces:
# Check if Face is on external Surface
if len(eachFace.getElements())==1:
numFaces=numFaces+1
faceNodes=eachFace.getNodes()
# Identify 'Fixed' Faces
fixed=1
try:
fSet=aPart.sets['Fixed']
for eachNode in faceNodes:
if eachNode not in fSet.nodes:
fixed=0
break
except:
fixed=0
pstring=pstring+str(fixed)+' '
# Write Element Nodes
eNodes=[]
for eachNode in eachFace.getElements()[0].getNodes():
pstring=pstring+str(eachNode.label)+' '
pstring=pstring+'\n'
# Write Each Face Nodes and Corresponding Connected Nodes
for eachNode in faceNodes:
pstring=pstring+str(eachNode.label)+' '
for eachEdge in eachNode.getElemEdges():
for eachENode in eachEdge.getNodes():
if eachENode.label != eachNode.label and eachENode in faceNodes:
pstring=pstring+str(eachENode.label)+' '
pstring=pstring+'\n'
incFile.write(str(numFaces)+'\n')
incFile.write(pstring)
incFile.close()
mdb.Job(name=jobName, model=mname)
mdb.jobs[jobName].writeInput(consistencyChecking=OFF)
mdb.close()