├── README.md └── Random_inclusions_2D.py /README.md: -------------------------------------------------------------------------------- 1 | # Random-inclusions_Abaqus-python-Part-2 2 | 3 | This is a code I used in following video: 4 | 5 | Creating Random Inclusions using python scripting | Python scripting in Abaqus part-2 6 | 7 | Link of video: https://youtu.be/ebJCgyfCWmE 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_2D.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 | dis=numpy.zeros(1000) 30 | 31 | rad=1.0 # radius of inclusion 32 | Max_iterations=11 # Set number of iterations 33 | 34 | max_incl = 25 # Set number of inclusions required 35 | 36 | for q in range (1,Max_iterations): 37 | # LET'S CREATE MODEL 38 | mdb.Model(modelType=STANDARD_EXPLICIT, name='Model-%d' %(q)) 39 | 40 | # LET'S CREATE PART 41 | mdb.models['Model-%d' %(q)].ConstrainedSketch(name='__profile__', sheetSize=20.0) 42 | mdb.models['Model-%d' %(q)].sketches['__profile__'].rectangle(point1=(-10.0, 10.0), 43 | point2=(10.0, -10.0)) 44 | mdb.models['Model-%d' %(q)].Part(dimensionality=TWO_D_PLANAR, name='Part-1', type= 45 | DEFORMABLE_BODY) 46 | mdb.models['Model-%d' %(q)].parts['Part-1'].BaseShell(sketch= 47 | mdb.models['Model-%d' %(q)].sketches['__profile__']) 48 | del mdb.models['Model-%d' %(q)].sketches['__profile__'] 49 | mdb.models['Model-%d' %(q)].ConstrainedSketch(gridSpacing=1.8, name='__profile__', 50 | sheetSize=20, transform= 51 | mdb.models['Model-%d' %(q)].parts['Part-1'].MakeSketchTransform( 52 | sketchPlane=mdb.models['Model-%d' %(q)].parts['Part-1'].faces[0], 53 | sketchPlaneSide=SIDE1, sketchOrientation=RIGHT, origin=(0.0, 0.0, 0.0))) 54 | mdb.models['Model-%d' %(q)].parts['Part-1'].projectReferencesOntoSketch(filter= 55 | COPLANAR_EDGES, sketch=mdb.models['Model-%d' %(q)].sketches['__profile__']) 56 | 57 | num_incl = 0 58 | x_coordinate = [] 59 | y_coordinate = [] 60 | 61 | while (num_incl < max_incl): 62 | random_x=random.uniform(-8.7, 8.7) #generate random x_coordinate within RVE 63 | random_y=random.uniform(-8.7, 8.7) #generate random y_coordinate within RVE 64 | 65 | isPointIntersecting = False 66 | # To check if new inclusion intersects with any existing inclusions 67 | for j in range (0,len(x_coordinate)): 68 | 69 | 70 | dis[j]=sqrt((random_x-x_coordinate[j])**2+(random_y-y_coordinate[j])**2) 71 | 72 | 73 | if dis[j] < (2.2*rad): 74 | 75 | isPointIntersecting = True 76 | break 77 | 78 | if (isPointIntersecting == False): 79 | x_coordinate.append(random_x) 80 | y_coordinate.append(random_y) 81 | num_incl = num_incl + 1 # count no of inclusions 82 | 83 | 84 | for i in range(max_incl): 85 | 86 | mdb.models['Model-%d' %(q)].sketches['__profile__'].CircleByCenterPerimeter(center=( 87 | x_coordinate[i], y_coordinate[i]), point1=((x_coordinate[i]-rad), y_coordinate[i])) 88 | 89 | mdb.models['Model-%d' %(q)].parts['Part-1'].PartitionFaceBySketch(faces= 90 | mdb.models['Model-%d' %(q)].parts['Part-1'].faces.findAt(((9.9, 91 | 9.9, 0.0), (0.0, 0.0, 1.0)), ), sketch=mdb.models['Model-%d' %(q)].sketches['__profile__']) 92 | 93 | 94 | # LET'S CREATE MATERIAL-1 (MATRIX POLYMER) 95 | mdb.models['Model-%d' %(q)].Material(name='Matrix') 96 | mdb.models['Model-%d' %(q)].materials['Matrix'].Elastic(table= 97 | ((1e2, 0.47), )) 98 | 99 | # LET'S CREATE MATERIAL-2 (ELASTIC INCLUSION) 100 | mdb.models['Model-%d' %(q)].Material(name='Elastic') 101 | mdb.models['Model-%d' %(q)].materials['Elastic'].Elastic(table= 102 | ((1e3, 0.35), )) 103 | 104 | # LET'S CREATE SECTIONS 105 | mdb.models['Model-%d' %(q)].HomogeneousSolidSection(material='Matrix', name='Matrix', 106 | thickness=None) 107 | mdb.models['Model-%d' %(q)].HomogeneousSolidSection(material='Elastic', name='Inclusion', 108 | thickness=None) 109 | 110 | # LET'S ASSIGN SECTIONS 111 | mdb.models['Model-%d' %(q)].parts['Part-1'].SectionAssignment(offset=0.0, 112 | offsetField='', offsetType=MIDDLE_SURFACE, region=Region( 113 | faces=mdb.models['Model-%d' %(q)].parts['Part-1'].faces.findAt(((9.9, 114 | 9.9, 0.0), (0.0, 0.0, 1.0)), )), sectionName='Matrix', 115 | thicknessAssignment=FROM_SECTION) 116 | 117 | for i in range (num_incl): 118 | mdb.models['Model-%d' %(q)].parts['Part-1'].SectionAssignment(offset=0.2, 119 | offsetField='', offsetType=MIDDLE_SURFACE, region=Region( 120 | faces=mdb.models['Model-%d' %(q)].parts['Part-1'].faces.findAt((((x_coordinate[i]), 121 | (y_coordinate[i]), 0.0), (0.0, 0.0, 1.0)), )), sectionName='Inclusion', 122 | thicknessAssignment=FROM_SECTION) 123 | 124 | # LET'S CREATE INSTANCE 125 | mdb.models['Model-%d' %(q)].rootAssembly.DatumCsysByDefault(CARTESIAN) 126 | mdb.models['Model-%d' %(q)].rootAssembly.Instance(dependent=OFF, name='Part-1-1', 127 | part=mdb.models['Model-%d' %(q)].parts['Part-1']) 128 | 129 | # LET'S CREATE STEP 130 | mdb.models['Model-%d' %(q)].StaticStep(initialInc=0.01, maxInc=0.1, maxNumInc=10000, 131 | minInc=1e-12, name='Step-1', previous='Initial') 132 | 133 | # LET'S CREATE BOUNDARY CONDITIONS 134 | mdb.models['Model-%d' %(q)].DisplacementBC(amplitude=UNSET, createStepName='Step-1', 135 | distributionType=UNIFORM, fieldName='', fixed=OFF, localCsys=None, name= 136 | 'BC-1', region=Region( 137 | edges=mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].edges.findAt( 138 | ((-5.0, -10.0, 0.0), ), )), u1=UNSET, u2=0.0, ur3=UNSET) 139 | mdb.models['Model-%d' %(q)].DisplacementBC(amplitude=UNSET, createStepName='Step-1', 140 | distributionType=UNIFORM, fieldName='', fixed=OFF, localCsys=None, name= 141 | 'BC-2', region=Region( 142 | edges=mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].edges.findAt( 143 | ((-10.0, 5.0, 0.0), ), )), u1=0.0, u2=UNSET, ur3=UNSET) 144 | mdb.models['Model-%d' %(q)].DisplacementBC(amplitude=UNSET, createStepName='Step-1', 145 | distributionType=UNIFORM, fieldName='', fixed=OFF, localCsys=None, name= 146 | 'BC-3', region=Region( 147 | edges=mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].edges.findAt( 148 | ((-5.0, 10.0, 0.0), ), )), u1=UNSET, u2=1.0, ur3=UNSET) 149 | 150 | # LET'S SEED THE INSTANCE 151 | mdb.models['Model-%d' %(q)].rootAssembly.seedPartInstance(deviationFactor=0.1, 152 | minSizeFactor=0.1, regions=( 153 | mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'], ), size=0.2) 154 | 155 | # LET'S SET ELEMENT TYPE 156 | for i in range (num_incl): 157 | mdb.models['Model-%d' %(q)].rootAssembly.setElementType(elemTypes=(ElemType( 158 | elemCode=CPE4R, elemLibrary=STANDARD), ElemType(elemCode=CPE3, 159 | elemLibrary=STANDARD)),regions=( 160 | mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].faces.findAt((( 161 | (x_coordinate[i]), (y_coordinate[i]), 0.0), )), )) 162 | 163 | mdb.models['Model-%d' %(q)].rootAssembly.setElementType(elemTypes=(ElemType( 164 | elemCode=CPE4R, elemLibrary=STANDARD), ElemType(elemCode=CPE3, 165 | elemLibrary=STANDARD)), regions=( 166 | mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].faces.findAt((( 167 | 9.9, 9.9, 0.0), )), )) 168 | 169 | # LET'S GENERATE MESH 170 | mdb.models['Model-%d' %(q)].rootAssembly.generateMesh(regions=( 171 | mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'], )) 172 | 173 | # LET'S CREATE SETS FOR EDGES 174 | mdb.models['Model-%d' %(q)].rootAssembly.Set(edges= 175 | mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].edges.findAt((( 176 | -5.0, -10.0, 0.0), )), name='BottomEdge') 177 | mdb.models['Model-%d' %(q)].rootAssembly.Set(edges= 178 | mdb.models['Model-%d' %(q)].rootAssembly.instances['Part-1-1'].edges.findAt((( 179 | -5.0, 10.0, 0.0), )), name='TopEdge') 180 | 181 | # LET'S CREATE HISTORY OUTPUT REQUESTS 182 | mdb.models['Model-%d' %(q)].HistoryOutputRequest(createStepName='Step-1', frequency=1 183 | , name='H-Output-2', rebar=EXCLUDE, region= 184 | mdb.models['Model-%d' %(q)].rootAssembly.sets['BottomEdge'], sectionPoints=DEFAULT, 185 | variables=('RF2',)) 186 | 187 | #LET'S CREATE JOBS 188 | mdb.Job(atTime=None, contactPrint=OFF, description='', echoPrint=OFF, 189 | explicitPrecision=SINGLE, getMemoryFromAnalysis=True, historyPrint=OFF, 190 | memory=90, memoryUnits=PERCENTAGE, model='Model-%d' %(q), modelPrint=OFF, 191 | multiprocessingMode=DEFAULT, name='Job-%d' %(q) , nodalOutputPrecision=SINGLE, 192 | numCpus=1, queue=None, scratch='', type=ANALYSIS, userSubroutine='', 193 | waitHours=0, waitMinutes=0) 194 | mdb.jobs['Job-%d' %(q)].writeInput() 195 | mdb.jobs['Job-%d' %(q) ].submit(consistencyChecking=OFF) 196 | mdb.jobs['Job-%d' %(q) ].waitForCompletion() 197 | 198 | #Property of Not Real Engineering 199 | --------------------------------------------------------------------------------