# Draw a Square Grain # def DrawSquare(VerModel,part_type,rad,extrude_depth): from abaqusConstants import * from abaqus import * label='Base' if part_type==3: VerPart=VerModel.Part(name=label, dimensionality=THREE_D,type=DEFORMABLE_BODY) else: VerPart=VerModel.Part(name=label, dimensionality=TWO_D_PLANAR,type=DEFORMABLE_BODY) VerPart.DatumPointByCoordinate((0,0,0)) VerPart.DatumPointByCoordinate((1,0,0)) VerPart.DatumPointByCoordinate((0,1,0)) pdatums=VerPart.datums VerPart.DatumPlaneByThreePoints(point1=pdatums[1], point2=pdatums[2], point3=pdatums[3]) VerPart.DatumAxisByTwoPoint(point1=pdatums[1],point2=pdatums[2]) partTransform = VerPart.MakeSketchTransform(sketchPlane=pdatums[4], sketchUpEdge=pdatums[5], sketchPlaneSide=SIDE1, sketchOrientation=BOTTOM, origin=(0,0,0)) VerSketch = VerModel.ConstrainedSketch(name=label,sheetSize=200, transform=partTransform) VerSketch.Line(point1=(0.,0.),point2=(rad,0.)) VerSketch.Line(point1=(rad,0.),point2=(rad,rad)) VerSketch.Line(point1=(rad,rad),point2=(0.,rad)) VerSketch.Line(point1=(0.,rad),point2=(0.,0.)) if part_type==3: VerPart.BaseSolidExtrude(sketch=VerSketch,depth=extrude_depth) else: VerPart.BaseShell(sketch=VerSketch) # Draw a Hexagonal Grain # def DrawHexagon(VerModel,part_type,rad,extrude_depth): from abaqusConstants import * from abaqus import * label='Base' VerAssembly=VerModel.rootAssembly if part_type==3: VerPart=VerModel.Part(name=label, dimensionality=THREE_D,type=DEFORMABLE_BODY) else: VerPart=VerModel.Part(name=label, dimensionality=TWO_D_PLANAR,type=DEFORMABLE_BODY) VerPart.DatumPointByCoordinate((0,0,0)) VerPart.DatumPointByCoordinate((1,0,0)) VerPart.DatumPointByCoordinate((0,1,0)) pdatums=VerPart.datums VerPart.DatumPlaneByThreePoints(point1=pdatums[1], point2=pdatums[2], point3=pdatums[3]) VerPart.DatumAxisByTwoPoint(point1=pdatums[1],point2=pdatums[2]) partTransform = VerPart.MakeSketchTransform(sketchPlane=pdatums[4], sketchUpEdge=pdatums[5], sketchPlaneSide=SIDE1, sketchOrientation=BOTTOM, origin=(0,0,0)) VerSketch = VerModel.ConstrainedSketch(name=label,sheetSize=200, transform=partTransform) yheight=sin(radians(30.)) xheight=cos(radians(30.)) VerSketch.Line(point1=(0.,0.),point2=(rad*xheight,rad*yheight)) VerSketch.Line(point1=(rad*xheight,rad*yheight),point2=(rad*xheight,rad*yheight+rad)) VerSketch.Line(point1=(rad*xheight,rad*yheight+rad),point2=(0.,2.*rad*yheight+rad)) VerSketch.Line(point1=(0.,2.*rad*yheight+rad),point2=(-rad*xheight,rad*yheight+rad)) VerSketch.Line(point1=(-rad*xheight,rad*yheight+rad),point2=(-rad*xheight,rad*yheight)) VerSketch.Line(point1=(-rad*xheight,rad*yheight),point2=(0.,0.)) if part_type==3: VerPart.BaseSolidExtrude(sketch=VerSketch,depth=extrude_depth) else: VerPart.BaseShell(sketch=VerSketch) BasePart=VerModel.parts['Base'] BasePartCells = BasePart.cells BasePartFaces = BasePart.faces BasePartVerts = BasePart.vertices if part_type==3: BasePart.PartitionCellByPlaneThreePoints(point1=BasePartVerts[4], point2=BasePartVerts[10], point3=BasePartVerts[11], cells=BasePartCells) else: BasePart.PartitionFaceByShortestPath(point1=BasePartVerts[4], point2=BasePartVerts[1], faces=BasePartFaces) # Draw a Dodecahedral Grain # def DrawDodec(VerModel,rad): from abaqusConstants import * from abaqus import * label='BaseTemp' VerAssembly=VerModel.rootAssembly VerPart=VerModel.Part(name=label, dimensionality=THREE_D,type=DEFORMABLE_BODY) VerPart.DatumPointByCoordinate((0,0,0)) VerPart.DatumPointByCoordinate((1,0,0)) VerPart.DatumPointByCoordinate((0,1,0)) pdatums=VerPart.datums VerPart.DatumPlaneByThreePoints(point1=pdatums[1], point2=pdatums[2], point3=pdatums[3]) VerPart.DatumAxisByTwoPoint(point1=pdatums[1],point2=pdatums[2]) partTransform = VerPart.MakeSketchTransform(sketchPlane=pdatums[4], sketchUpEdge=pdatums[5], sketchPlaneSide=SIDE1, sketchOrientation=BOTTOM, origin=(0,0,0)) VerSketch = VerModel.ConstrainedSketch(name=label,sheetSize=200, transform=partTransform) VerSketch.Line(point1=(0.,0.),point2=(sqrt(2.)*rad,rad)) VerSketch.Line(point1=(sqrt(2.)*rad,rad),point2=(0.,2.*rad)) VerSketch.Line(point1=(0.,2.*rad),point2=(-sqrt(2.)*rad,rad)) VerSketch.Line(point1=(-sqrt(2.)*rad,rad),point2=(0.,0.)) VerPart.BaseShell(sketch=VerSketch) for i in range (1,13): dodecname='dodec'+str(i) VerAssembly.Instance(name=dodecname,part=VerPart, dependent=ON) VerAssembly.translate(instanceList=('dodec2', ), vector=(0.,0.,-2.*sqrt(2.)*rad)) VerAssembly.rotate(instanceList=('dodec3','dodec4', ), axisPoint=(0.0, 0.0, 0.0), axisDirection=(0.0, 1., 0.0), angle=90.0) VerAssembly.translate(instanceList=('dodec3', ), vector=(sqrt(2.)*rad,0.,0.)) VerAssembly.translate(instanceList=('dodec4', ), vector=(-sqrt(2.)*rad,0.,0.)) VerAssembly.translate(instanceList=('dodec3','dodec4', ), vector=(0.,0.,-sqrt(2.)*rad)) VerAssembly.rotate(instanceList=('dodec5','dodec6','dodec7','dodec8',), axisPoint=(-sqrt(2.)*rad, rad, 0.0), axisDirection=(0., 0., 1.), angle=90.0) VerAssembly.rotate(instanceList=('dodec5','dodec6','dodec7','dodec8',), axisPoint=(-sqrt(2.)*rad, rad, 0.0), axisDirection=(0., 1., 0.), angle=-45.0) VerAssembly.rotate(instanceList=('dodec5','dodec6','dodec7','dodec8',), axisPoint=(-sqrt(2.)*rad, rad, 0.0), axisDirection=(1., 0., 1.), angle=-45.0) VerAssembly.rotate(instanceList=('dodec6',), axisPoint=(0., rad, -sqrt(2.)*rad), axisDirection=(0., 1., 0.), angle=90.0) VerAssembly.rotate(instanceList=('dodec7',), axisPoint=(0., rad, -sqrt(2.)*rad), axisDirection=(0., 1., 0.), angle=180.0) VerAssembly.rotate(instanceList=('dodec8',), axisPoint=(0., rad, -sqrt(2.)*rad), axisDirection=(0., 1., 0.), angle=270.0) VerAssembly.rotate(instanceList=('dodec9','dodec10','dodec11','dodec12',), axisPoint=(-sqrt(2.)*rad, rad, 0.0), axisDirection=(0., 0., 1.), angle=-90.0) VerAssembly.rotate(instanceList=('dodec9','dodec10','dodec11','dodec12',), axisPoint=(-sqrt(2.)*rad, rad, 0.0), axisDirection=(0., 1., 0.), angle=-45.0) VerAssembly.rotate(instanceList=('dodec9','dodec10','dodec11','dodec12',), axisPoint=(-sqrt(2.)*rad, rad, 0.0), axisDirection=(1., 0., 1.), angle=45.0) VerAssembly.rotate(instanceList=('dodec10',), axisPoint=(0., rad, -sqrt(2.)*rad), axisDirection=(0., -1., 0.), angle=90.0) VerAssembly.rotate(instanceList=('dodec11',), axisPoint=(0., rad, -sqrt(2.)*rad), axisDirection=(0., -1., 0.), angle=180.0) VerAssembly.rotate(instanceList=('dodec12',), axisPoint=(0., rad, -sqrt(2.)*rad), axisDirection=(0., -1., 0.), angle=270.0) VerAssembly.InstanceFromBooleanMerge(name='Base', instances=( VerAssembly.instances['dodec1'], VerAssembly.instances['dodec2'], VerAssembly.instances['dodec3'], VerAssembly.instances['dodec4'], VerAssembly.instances['dodec5'], VerAssembly.instances['dodec6'], VerAssembly.instances['dodec7'], VerAssembly.instances['dodec8'], VerAssembly.instances['dodec9'], VerAssembly.instances['dodec10'],VerAssembly.instances['dodec11'], VerAssembly.instances['dodec12'], ), keepIntersections=ON, originalInstances=SUPPRESS, domain=GEOMETRY) VerPart=VerModel.parts['Base'] VerPart.AddCells(faceList = VerPart.faces) for i in range (1,12): dodecname='dodec'+str(i) del VerAssembly.instances[dodecname] del VerAssembly.instances['Base-1'] # Draw a 2D Voronoi Tessellation # def Voronoi2D(VerModel,part_type,extrude_depth,num_grains,maxsize,hard_rad,random_seed): from abaqusConstants import * from abaqus import * import random import subprocess xlist=[0.] ylist=[0.] VerAssembly=VerModel.rootAssembly random.seed(random_seed) qhullin=open('qhullin.dat','w') qhullin.write("%i \n"%(2)) qhullin.write("%i \n"%(num_grains*9)) for i in range(0,num_grains): outside=False while outside==False: xcor=random.random()*maxsize ycor=random.random()*maxsize if hard_rad==0.: outside=True break if len(xlist)>1: distold=1000. for i in range(1,len(xlist)): distnew=(xcor-xlist[i])*(xcor-xlist[i])+(ycor-ylist[i])*(ycor-ylist[i]) distnew=sqrt(distnew) if distnew=hard_rad: outside=True else: outside=True xlist.append(xcor) ylist.append(ycor) qhullin.write("%18.6f %18.6f \n"%(xcor,ycor)) qhullin.write("%18.6f %18.6f \n"%(xcor+maxsize,ycor)) qhullin.write("%18.6f %18.6f \n"%(xcor-maxsize,ycor)) qhullin.write("%18.6f %18.6f \n"%(xcor,ycor+maxsize)) qhullin.write("%18.6f %18.6f \n"%(xcor,ycor-maxsize)) qhullin.write("%18.6f %18.6f \n"%(xcor+maxsize,ycor+maxsize)) qhullin.write("%18.6f %18.6f \n"%(xcor-maxsize,ycor-maxsize)) qhullin.write("%18.6f %18.6f \n"%(xcor+maxsize,ycor-maxsize)) qhullin.write("%18.6f %18.6f \n"%(xcor-maxsize,ycor+maxsize)) qhullin.close() scales=open('scales.dat','w') scales.write("%18.6f \n"%(maxsize)) scales.close() # retcode=subprocess.call("qhull.exe v Qbb TI qhullin.dat o TO qhullout.dat") retcode=subprocess.call("Voronoi2DPost.exe") FortranFile=open('fortranout.dat') num_cells=int(FortranFile.readline()) cordx=[] cordy=[] x1=[] y1=[] x2=[] y2=[] k=0 for i in range(0,num_cells): label='Cell'+str(i) if part_type==3: VerPart=VerModel.Part(name=label, dimensionality=THREE_D,type=DEFORMABLE_BODY) else: VerPart=VerModel.Part(name=label, dimensionality=TWO_D_PLANAR,type=DEFORMABLE_BODY) # Constuct Datum Point At Each Node VerPart.DatumPointByCoordinate((0,0,0)) VerPart.DatumPointByCoordinate((1,0,0)) VerPart.DatumPointByCoordinate((0,1,0)) pdatums=VerPart.datums # Constuct Datum Plane on Element Face and Datum Axis Along Element Base VerPart.DatumPlaneByThreePoints(point1=pdatums[1], point2=pdatums[2], point3=pdatums[3]) VerPart.DatumAxisByTwoPoint(point1=pdatums[1],point2=pdatums[2]) # Sketch New Part Geometry Over Original Element partTransform = VerPart.MakeSketchTransform(sketchPlane=pdatums[4], sketchUpEdge=pdatums[5], sketchPlaneSide=SIDE1, sketchOrientation=BOTTOM, origin=(0,0,0)) VerSketch = VerModel.ConstrainedSketch(name=label,sheetSize=200, transform=partTransform) num_verts=int(FortranFile.readline()) for j in range(0,num_verts): coords=FortranFile.readline().split(',') cordx.append([]) cordy.append([]) cordx[j]=float(coords[0]) cordy[j]=float(coords[1]) print i,num_verts for j in range(0,num_verts-1): VerSketch.Line(point1=(cordx[j],cordy[j]),point2=(cordx[j+1],cordy[j+1])) x1.append([]) y1.append([]) x1[k]=cordx[j] y1[k]=cordy[j] x2.append([]) y2.append([]) x2[k]=cordx[j+1] y2[k]=cordy[j+1] k=k+1 VerSketch.Line(point1=(cordx[num_verts-1],cordy[num_verts-1]), point2=(cordx[0],cordy[0])) x1.append([]) y1.append([]) x1[k]=cordx[num_verts-1] y1[k]=cordy[num_verts-1] x2.append([]) y2.append([]) x2[k]=cordx[0] y2[k]=cordy[0] k=k+1 print i,num_verts,k if part_type==3: VerPart.BaseSolidExtrude(sketch=VerSketch, depth=extrude_depth) else: VerPart.Shell(sketchPlane=pdatums[4], sketchUpEdge=pdatums[5], sketchPlaneSide=SIDE1, sketchOrientation=BOTTOM, sketch=VerSketch) VerAssembly.Instance(name=label,part=VerPart) inst=[] inst.append([]) for i in range(0,num_cells): inst[i]=VerAssembly.instances['Cell'+str(i)] if i1: distold=1000. for i in range(1,len(xlist)): distnew=(xcor-xlist[i])*(xcor-xlist[i])+(ycor-ylist[i])*(ycor-ylist[i]) distnew=distnew+(zcor-zlist[i])*(zcor-zlist[i]) distnew=sqrt(distnew) if distnew=hard_rad: outside=True else: outside=True xlist.append(xcor) ylist.append(ycor) zlist.append(zcor) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor,ycor,zcor)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor+maxsize,ycor,zcor)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor-maxsize,ycor,zcor)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor,ycor+maxsize,zcor)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor,ycor-maxsize,zcor)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor+maxsize,ycor+maxsize,zcor)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor-maxsize,ycor-maxsize,zcor)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor+maxsize,ycor-maxsize,zcor)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor-maxsize,ycor+maxsize,zcor)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor,ycor,zcor+maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor+maxsize,ycor,zcor+maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor-maxsize,ycor,zcor+maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor,ycor+maxsize,zcor+maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor,ycor-maxsize,zcor+maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor+maxsize,ycor+maxsize,zcor+maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor-maxsize,ycor-maxsize,zcor+maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor+maxsize,ycor-maxsize,zcor+maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor-maxsize,ycor+maxsize,zcor+maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor,ycor,zcor-maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor+maxsize,ycor,zcor-maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor-maxsize,ycor,zcor-maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor,ycor+maxsize,zcor-maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor,ycor-maxsize,zcor-maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor+maxsize,ycor+maxsize,zcor-maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor-maxsize,ycor-maxsize,zcor-maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor+maxsize,ycor-maxsize,zcor-maxsize)) qhullin.write("%18.6f %18.6f %18.6f \n"%(xcor-maxsize,ycor+maxsize,zcor-maxsize)) qhullin.close() scales=open('scales.dat','w') scales.write("%18.6f \n"%(maxsize)) scales.close() # retcode=subprocess.call("qvoronoi.exe TI qhullin.dat o Fi TO qhullout.dat") retcode=subprocess.call("Voronoi3DPost.exe") FortranFile=open('fortranout.dat') num_cells=int(FortranFile.readline()) cordx=[] cordy=[] cordz=[] x1=[] y1=[] x2=[] y2=[] k=0 for k in range(0,num_cells): num_hyp=int(FortranFile.readline()) for i in range(0,num_hyp): label='C'+str(k)+'H'+str(i) VerPart=VerModel.Part(name=label, dimensionality=THREE_D,type=DEFORMABLE_BODY) # Constuct Datum Point At Each Node num_verts=int(FortranFile.readline()) for j in range(0,num_verts): coords=FortranFile.readline().split(',') cordx.append([]) cordy.append([]) cordz.append([]) cordx[j]=float(coords[0]) cordy[j]=float(coords[1]) cordz[j]=float(coords[2]) VerPart.DatumPointByCoordinate((cordx[j],cordy[j],cordz[j])) pdatums=VerPart.datums p1x=pdatums[1].pointOn[0] p1y=pdatums[1].pointOn[1] p1z=pdatums[1].pointOn[2] tol=1.e-4 for m in range(2,num_verts+1): px=pdatums[m].pointOn[0] py=pdatums[m].pointOn[1] pz=pdatums[m].pointOn[2] p1pk=sqrt((p1x-px)*(p1x-px)+(p1y-py)*(p1y-py)+(p1z-pz)*(p1z-pz)) if p1pk>tol: index1=m p2x=px p2y=py p2z=pz break for m in range(2,num_verts+1): if m!=index1: px=pdatums[m].pointOn[0] py=pdatums[m].pointOn[1] pz=pdatums[m].pointOn[2] p1pk=sqrt((p1x-px)*(p1x-px)+(p1y-py)*(p1y-py)+(p1z-pz)*(p1z-pz)) p2pk=sqrt((p2x-px)*(p2x-px)+(p2y-py)*(p2y-py)+(p2z-pz)*(p2z-pz)) if p1pk>tol: if p2pk>tol: index2=m break VerPart.DatumPlaneByThreePoints(point1=pdatums[1], point2=pdatums[index1], point3=pdatums[index2]) VerPart.DatumAxisByTwoPoint(point1=pdatums[1],point2=pdatums[index1]) partTransform = VerPart.MakeSketchTransform(sketchPlane=pdatums[num_verts+1], sketchUpEdge=pdatums[num_verts+2], sketchPlaneSide=SIDE1, sketchOrientation=BOTTOM, origin=(0.,0.,0.)) sklabel='Skbase'+'C'+str(k)+'H'+str(i) VerSketch=VerModel.ConstrainedSketch(name=sklabel,sheetSize=200, transform=partTransform) VerPart.projectReferencesOntoSketch(sketch=VerSketch, filter=COPLANAR_EDGES) verts=VerSketch.vertices centroidx=0. centroidy=0. angle=[] jnum=[] for j in range(0,num_verts): centroidx=centroidx+verts[j].coords[0] centroidy=centroidy+verts[j].coords[1] centroidx=centroidx/float(num_verts) centroidy=centroidy/float(num_verts) for j in range(0,num_verts): pointx=verts[j].coords[0]-centroidx pointy=verts[j].coords[1]-centroidy vertangle=atan2(pointy,pointx) if vertangle<0.: vertangle=2*pi+vertangle angle.append(vertangle) jnum.append(j) icheck=0 while icheck==0: icheck=1 for j in range(1,num_verts): if angle[j]