├── README.md └── Random_inclusions_3D.py /README.md: -------------------------------------------------------------------------------- 1 | # Random-Inclusions-using-python-scripting-3D-RVE 2 | 3 | This is a code I used in following video: 4 | 5 | Random spherical inclusions in 3D RVE using python scripting in Abaqus 6 | 7 | Link of video: 8 | 9 | Email: notrealengineering@gmail.com 10 | 11 | Copyright © 2020 Not Real Engineering - All Rights Reserved You may not use, distribute and modify this code without the written permission from Not Real Engineering. 12 | -------------------------------------------------------------------------------- /Random_inclusions_3D.py: -------------------------------------------------------------------------------- 1 | #Property of Not Real Engineering 2 | #Copyright 2020 Not Real Engineering - All Rights Reserved You may not use, 3 | # distribute and modify this code without the written permission 4 | # from Not Real Engineering. 5 | ############################################################################ 6 | ## Creating Random Inclusions ## 7 | ############################################################################ 8 | 9 | from part import * 10 | from material import * 11 | from section import * 12 | from assembly import * 13 | from step import * 14 | from interaction import * 15 | from load import * 16 | from mesh import * 17 | from optimization import * 18 | from job import * 19 | from sketch import * 20 | from visualization import * 21 | from connectorBehavior import * 22 | import random 23 | from array import * 24 | import math 25 | import numpy 26 | import os # Operating system 27 | import shutil # copying or moving files 28 | 29 | global rad; 30 | rad = 2.0 # radius of inclusion 31 | 32 | def partition(i,q): 33 | a=rad*sin(pi/6) 34 | b=rad*cos(pi/6) 35 | ## Creating Datum Planes 1 36 | dp1=mdb.models['Model-%d' %(q)].parts['Part-1'].DatumPlaneByPrincipalPlane(offset=x_coordinate[i], principalPlane=YZPLANE) 37 | dp2=mdb.models['Model-%d' %(q)].parts['Part-1'].DatumPlaneByPrincipalPlane(offset=y_coordinate[i], principalPlane=XZPLANE) 38 | 39 | ## Creating Partition profile 2 40 | mdb.models['Model-%d' %(q)].ConstrainedSketch(gridSpacing=2.0, name='__profile__', sheetSize=25.0, transform= 41 | mdb.models['Model-%d' %(q)].parts['Part-1'].MakeSketchTransform( 42 | sketchPlane=mdb.models['Model-%d' %(q)].parts['Part-1'].datums[dp1.id], sketchPlaneSide=SIDE1, 43 | sketchUpEdge=mdb.models['Model-%d' %(q)].parts['Part-1'].edges.findAt((0.0, 0.0, 5.0), ), sketchOrientation=TOP, origin=(x_coordinate[i],y_coordinate[i],z_coordinate[i]))) 44 | mdb.models['Model-%d' %(q)].parts['Part-1'].projectReferencesOntoSketch(filter=COPLANAR_EDGES, sketch=mdb.models['Model-%d' %(q)].sketches['__profile__']) 45 | c_1=mdb.models['Model-%d' %(q)].sketches['__profile__'].ArcByCenterEnds(center=(0,0), direction=CLOCKWISE, point1=(0,rad), point2=(rad,0)) 46 | 47 | c_2=mdb.models['Model-%d' %(q)].sketches['__profile__'].ArcByCenterEnds(center=(0,0), direction=CLOCKWISE, point1=(rad,0), point2=(0,-rad)) 48 | 49 | mdb.models['Model-%d' %(q)].sketches['__profile__'].Line(point1=(0,rad), point2=(0,-rad)) 50 | mdb.models['Model-%d' %(q)].parts['Part-1'].PartitionCellBySketch(cells= 51 | mdb.models['Model-%d' %(q)].parts['Part-1'].cells.findAt(((0.1, 0.1,0.1), )), sketch=mdb.models['Model-%d' %(q)].sketches['__profile__'], 52 | sketchOrientation=TOP, sketchPlane=mdb.models['Model-%d' %(q)].parts['Part-1'].datums[dp1.id], sketchUpEdge=mdb.models['Model-%d' %(q)].parts['Part-1'].edges.findAt((0.0, 0.0, 5.0), )) 53 | 54 | ## Creating circle for giving path to sweep 55 | mdb.models['Model-%d' %(q)].ConstrainedSketch(gridSpacing=2.0, name='__profile__', sheetSize=25.0, 56 | transform=mdb.models['Model-%d' %(q)].parts['Part-1'].MakeSketchTransform(sketchPlane=mdb.models['Model-%d' %(q)].parts['Part-1'].datums[dp2.id], 57 | sketchPlaneSide=SIDE1,sketchUpEdge=mdb.models['Model-%d' %(q)].parts['Part-1'].edges.findAt((0.0, 0.0, 5.0), ), sketchOrientation=TOP, origin=(x_coordinate[i], y_coordinate[i], z_coordinate[i]))) 58 | mdb.models['Model-%d' %(q)].parts['Part-1'].projectReferencesOntoSketch(filter=COPLANAR_EDGES,sketch=mdb.models['Model-%d' %(q)].sketches['__profile__']) 59 | c_3=mdb.models['Model-%d' %(q)].sketches['__profile__'].CircleByCenterPerimeter(center=(0, 0), point1=(-rad, 0)) 60 | 61 | mdb.models['Model-%d' %(q)].parts['Part-1'].PartitionCellBySketch(cells=mdb.models['Model-%d' %(q)].parts['Part-1'].cells.findAt(((0.2,0.2, 62 | 0.2), )), sketch=mdb.models['Model-%d' %(q)].sketches['__profile__'],sketchOrientation=TOP, sketchPlane= 63 | mdb.models['Model-%d' %(q)].parts['Part-1'].datums[dp2.id], sketchUpEdge=mdb.models['Model-%d' %(q)].parts['Part-1'].edges.findAt((0.0, 0.0, 5.0), )) 64 | 65 | ## Creating the spherical partition 66 | m= mdb.models['Model-%d' %(q)].parts['Part-1'] 67 | m.PartitionCellBySweepEdge(sweepPath=m.edges.findAt((x_coordinate[i]+rad, y_coordinate[i], z_coordinate[i]),),cells=m.cells.findAt((0.2, 0.2, 0.2),),edges=(m.edges.findAt((x_coordinate[i], y_coordinate[i]-a,z_coordinate[i]+b), ),)) 68 | m.PartitionCellBySweepEdge(sweepPath=m.edges.findAt((x_coordinate[i]+rad, y_coordinate[i], z_coordinate[i]),),cells=m.cells.findAt((0.2, 0.2, 0.2),),edges=(m.edges.findAt((x_coordinate[i], y_coordinate[i]+a,z_coordinate[i]+b), ),)) 69 | 70 | dis=numpy.zeros(1000) 71 | 72 | Max_iterations=4 # Set number of iterations 73 | max_incl = 15 # set number of inclusions required 74 | 75 | for q in range (1,Max_iterations): 76 | # LET'S CREATE MODEL 77 | mdb.Model(modelType=STANDARD_EXPLICIT, name='Model-%d' %(q)) 78 | 79 | ## LETS CREATE MATRIX 80 | mdb.models['Model-%d' %(q)].ConstrainedSketch(name='__profile__', sheetSize=20.0) 81 | mdb.models['Model-%d' %(q)].sketches['__profile__'].sketchOptions.setValues( 82 | decimalPlaces=4) 83 | mdb.models['Model-%d' %(q)].sketches['__profile__'].rectangle(point1=(0.0, 0.0), 84 | point2=(20.0, 20.0)) 85 | mdb.models['Model-%d' %(q)].Part(dimensionality=THREE_D, name='Part-1', type= 86 | DEFORMABLE_BODY) 87 | mdb.models['Model-%d' %(q)].parts['Part-1'].BaseSolidExtrude(depth=20.0, sketch= 88 | mdb.models['Model-%d' %(q)].sketches['__profile__']) 89 | del mdb.models['Model-%d' %(q)].sketches['__profile__'] 90 | 91 | num_incl = 0 92 | x_coordinate = [] 93 | y_coordinate = [] 94 | z_coordinate = [] 95 | 96 | while (num_incl < max_incl): 97 | random_x=random.uniform(3.3, 16.7) 98 | random_y=random.uniform(3.3, 16.7) 99 | random_z=random.uniform(3.3, 16.7) 100 | 101 | isPointIntersecting = False 102 | for j in range (0,len(x_coordinate)): 103 | 104 | 105 | dis[j]=sqrt((random_x-x_coordinate[j])**2+(random_y-y_coordinate[j])**2+(random_z-z_coordinate[j])**2) 106 | 107 | 108 | if dis[j] < (2.2*rad): 109 | 110 | isPointIntersecting = True 111 | break 112 | 113 | if (isPointIntersecting == False): 114 | x_coordinate.append(random_x) 115 | y_coordinate.append(random_y) 116 | z_coordinate.append(random_z) 117 | num_incl = num_incl + 1 118 | 119 | for i in range (num_incl): 120 | partition(i,q) 121 | 122 | # LET'S CREATE MATERIAL-1 (MATRIX POLYMER) 123 | mdb.models['Model-%d' %(q)].Material(name='Matrix') 124 | mdb.models['Model-%d' %(q)].materials['Matrix'].Elastic(table= 125 | ((1e2, 0.47), )) 126 | 127 | # LET'S CREATE MATERIAL-2 (ELASTIC INCLUSION) 128 | mdb.models['Model-%d' %(q)].Material(name='Elastic') 129 | mdb.models['Model-%d' %(q)].materials['Elastic'].Elastic(table= 130 | ((1e3, 0.35), )) 131 | 132 | # LET'S CREATE SECTIONS 133 | mdb.models['Model-%d' %(q)].HomogeneousSolidSection(material='Matrix', name='Matrix', 134 | thickness=None) 135 | mdb.models['Model-%d' %(q)].HomogeneousSolidSection(material='Elastic', name='Inclusion', 136 | thickness=None) 137 | 138 | # LET'S ASSIGN SECTIONS 139 | mdb.models['Model-%d' %(q)].parts['Part-1'].SectionAssignment(offset=0.0, 140 | offsetField='', offsetType=MIDDLE_SURFACE, region=Region( 141 | cells=mdb.models['Model-%d' %(q)].parts['Part-1'].cells.findAt(((0.1, 0.1, 0.1), ), )), sectionName='Matrix', 142 | thicknessAssignment=FROM_SECTION) 143 | 144 | for i in range (num_incl): 145 | mdb.models['Model-%d' %(q)].parts['Part-1'].SectionAssignment(offset=0.0, 146 | offsetField='', offsetType=MIDDLE_SURFACE, region=Region( 147 | cells=mdb.models['Model-%d' %(q)].parts['Part-1'].cells.findAt(((x_coordinate[i], y_coordinate[i]-0.2*rad, z_coordinate[i]+0.2*rad), ), )), 148 | sectionName='Inclusion', thicknessAssignment=FROM_SECTION) 149 | mdb.models['Model-%d' %(q)].parts['Part-1'].SectionAssignment(offset=0.0, 150 | offsetField='', offsetType=MIDDLE_SURFACE, region=Region( 151 | cells=mdb.models['Model-%d' %(q)].parts['Part-1'].cells.findAt(((x_coordinate[i], y_coordinate[i]+0.2*rad, z_coordinate[i]+0.2*rad), ), )), 152 | sectionName='Inclusion', thicknessAssignment=FROM_SECTION) 153 | 154 | # LET'S CREATE INSTANCE 155 | mdb.models['Model-%d' %(q)].rootAssembly.DatumCsysByDefault(CARTESIAN) 156 | mdb.models['Model-%d' %(q)].rootAssembly.Instance(dependent=ON, name='Part-1-1', 157 | part=mdb.models['Model-%d' %(q)].parts['Part-1']) 158 | 159 | # LET'S CREATE STEP 160 | mdb.models['Model-%d' %(q)].StaticStep(initialInc=0.01, maxInc=0.1, maxNumInc=10000, 161 | minInc=1e-12, name='Step-1', previous='Initial') 162 | 163 | # LET'S CREATE BOUNDARY CONDITIONS 164 | mdb.models['Model-%d' %(q)].DisplacementBC(amplitude=UNSET, createStepName='Step-1', 165 | distributionType=UNIFORM, fieldName='', fixed=OFF, localCsys=None, name= 166 | 'BC-1', region=Region( 167 | faces=mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].faces.findAt( 168 | ((0.0, 1.0, 5.0), ), )), u1=0.0, u2=UNSET, u3=UNSET, ur1=UNSET, 169 | ur2=UNSET, ur3=UNSET) 170 | 171 | mdb.models['Model-%d' %(q)].DisplacementBC(amplitude=UNSET, createStepName='Step-1', 172 | distributionType=UNIFORM, fieldName='', fixed=OFF, localCsys=None, name= 173 | 'BC-2', region=Region( 174 | faces=mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].faces.findAt( 175 | ((1.0, 0.0, 5.0), ), )), u1=UNSET, u2=0.0, u3=UNSET, ur1=UNSET, 176 | ur2=UNSET, ur3=UNSET) 177 | 178 | mdb.models['Model-%d' %(q)].DisplacementBC(amplitude=UNSET, createStepName='Step-1', 179 | distributionType=UNIFORM, fieldName='', fixed=OFF, localCsys=None, name= 180 | 'BC-3', region=Region( 181 | faces=mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].faces.findAt( 182 | ((5.0, 5.0, 0.0), ), )), u1=UNSET, u2=UNSET, u3=0.0, ur1=UNSET, 183 | ur2=UNSET, ur3=UNSET) 184 | 185 | mdb.models['Model-%d' %(q)].DisplacementBC(amplitude=UNSET, createStepName='Step-1', 186 | distributionType=UNIFORM, fieldName='', fixed=OFF, localCsys=None, name= 187 | 'BC-4', region=Region( 188 | faces=mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].faces.findAt( 189 | ((20.0, 5.0, 5.0), ), )), u1=0.1, u2=UNSET, u3=UNSET, ur1=UNSET, 190 | ur2=UNSET, ur3=UNSET) 191 | 192 | # LET'S SEED THE PART 193 | mdb.models['Model-%d' %(q)].parts['Part-1'].seedPart(deviationFactor=0.1, 194 | minSizeFactor=0.1, size=1.0) 195 | 196 | # LET'S SET ELEMENT TYPE 197 | mdb.models['Model-%d' %(q)].parts['Part-1'].setElementType(elemTypes=(ElemType( 198 | elemCode=C3D8, elemLibrary=STANDARD), ElemType(elemCode=C3D6, 199 | elemLibrary=STANDARD), ElemType(elemCode=C3D4, elemLibrary=STANDARD)), 200 | regions=(mdb.models['Model-%d' %(q)].parts['Part-1'].cells.findAt(((0.1,0.1,0.1), ), ), )) 201 | 202 | for i in range (num_incl): 203 | mdb.models['Model-%d' %(q)].parts['Part-1'].setElementType(elemTypes=(ElemType(elemCode=C3D8, elemLibrary=STANDARD), ElemType(elemCode=C3D6, 204 | elemLibrary=STANDARD), ElemType(elemCode=C3D4, elemLibrary=STANDARD)), 205 | regions=(mdb.models['Model-%d' %(q)].parts['Part-1'].cells.findAt(((x_coordinate[i],y_coordinate[i]-0.2*rad,z_coordinate[i]+0.2*rad), ), ((x_coordinate[i],y_coordinate[i]+0.2*rad,z_coordinate[i]+0.2*rad), ), ), )) 206 | 207 | mdb.models['Model-%d' %(q)].parts['Part-1'].setMeshControls(elemShape=TET, regions= 208 | mdb.models['Model-%d' %(q)].parts['Part-1'].cells.findAt(((0.1, 0.1, 0.1), ), ), technique=FREE) 209 | 210 | for i in range (num_incl): 211 | mdb.models['Model-%d' %(q)].parts['Part-1'].setMeshControls(elemShape=TET, regions= 212 | mdb.models['Model-%d' %(q)].parts['Part-1'].cells.findAt(((x_coordinate[i],y_coordinate[i]-0.2*rad,z_coordinate[i]+0.2*rad), ), ((x_coordinate[i],y_coordinate[i]+0.2*rad,z_coordinate[i]+0.2*rad), ), ), technique=FREE) 213 | mdb.models['Model-%d' %(q)].parts['Part-1'].setMeshControls(elemShape=TET, regions= 214 | mdb.models['Model-%d' %(q)].parts['Part-1'].cells.findAt(((x_coordinate[i],y_coordinate[i]-1.05*rad,z_coordinate[i]), ), ((x_coordinate[i],y_coordinate[i]+1.05*rad,z_coordinate[i]), ), ), technique=FREE) 215 | 216 | # LET'S GENERATE MESH 217 | mdb.models['Model-%d' %(q)].parts['Part-1'].generateMesh() 218 | 219 | #LET'S CREATE JOBS 220 | mdb.Job(atTime=None, contactPrint=OFF, description='', echoPrint=OFF, 221 | explicitPrecision=SINGLE, getMemoryFromAnalysis=True, historyPrint=OFF, 222 | memory=90, memoryUnits=PERCENTAGE, model='Model-%d' %(q), modelPrint=OFF, 223 | multiprocessingMode=DEFAULT, name='Job-%d' %(q) , nodalOutputPrecision=SINGLE, 224 | numCpus=1, queue=None, scratch='', type=ANALYSIS, userSubroutine='', 225 | waitHours=0, waitMinutes=0) 226 | #mdb.jobs['Job-%d-%d' %(w,q)].writeInput() 227 | #mdb.jobs['Job-%d-%d' %(w,q) ].submit(consistencyChecking=OFF) 228 | #mdb.jobs['Job-%d-%d' %(w,q) ].waitForCompletion() 229 | 230 | 231 | #Property of Not Real Engineering 232 | --------------------------------------------------------------------------------