I_shape = [] J_shape = [] old_vfrac = 0. J = 0 # counter for the number of particles placed in the mesh try: while vol_placed_frac < vol_frac: # Keep attempting to add particles until the required volume fraction is achieved if J == 0 or (vol_placed_frac < vfraclimit * vol_frac ): # FIRST PARTICLE must ALWAYS be randomly placed I = random.randint( nmin, nmax ) # Generate a rrandom number to randomly select a particle from the 'library' fail = 1 while fail == 1: # Whilst fail = True continue to try to generate a coordinate x, y, fail = pss.gen_coord(pss.mesh_Shps[I, :, :]) area = pss.insert_shape_into_mesh(pss.mesh_Shps[I, :, :], x, y) J += 1 else: I = random.randint( nmin, nmax ) # Generate a random number to randomly select one of the generated shapes, to be tried for this loop x, y, area = pss.drop_shape_into_mesh(pss.mesh_Shps[I, :, :]) J += 1 placed_part_area.append(area) # Save the area xcoords.append(x) # Save the coords of that particle ycoords.append(y) radii.append(part_radii[I]) # Save the radii J_shape.append(J) # Save the particle number
xc = [] # x coord yc = [] # y coord I_ = [] # Library index J_ = [] # shape number of each placed particle vf_pld = 0 # Volume Fraction of material inserted into the mesh so far J = 0 old_vfrac = 0. try: # Begin loop placing grains in. while vf_pld < vol_frac: # Keep attempting to add particles until the required volume fraction is achieved I = random.randint( 0, n - 1 ) # Generate a random index to randomly select a particle from the 'library' fail = 1 while fail == 1: # Whilst fail == 1 continue to try to generate a coordinate x, y, fail = pss.gen_coord( pss.mesh_Shps[I, :, :] ) # Function generates a coordinate where the placed shape does not overlap with any placed so far area = pss.insert_shape_into_mesh(pss.mesh_Shps[I, :, :], x, y) J += 1 # pss.place_shape(pss.mesh_Shps[0,:,:],J,I,M) # This function allows you to place a shape in AND specify its material. However it overwrites previous placings A_.append(area) # Save the area xc.append(x) # Save the coords of that particle yc.append(y) J_.append(J) # Save the particle number I_.append(I) # Save the library index vf_pld = np.sum(A_) / (pss.meshx * pss.meshy ) # update the volume fraction if vf_pld == old_vfrac: print '##########~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##########' print '# volume fraction no longer increasing. Break here #'
nmin = 0 nmax = n-1 # max integer generated xcoords = [] ycoords = [] radii = [] I_shape = [] J_shape = [] old_vfrac = 0. try: while vol_placed_frac<vol_frac: # Keep attempting to add particles until the required volume fraction is achieved if J == 0: # FIRST PARTICLE must ALWAYS be randomly placed I = random.randint(nmin,nmax) # Generate a random number to randomly select one of the generated shapes, to be tried for this loop fail = 1 while fail == 1: x,y,fail = pss.gen_coord(pss.mesh_Shps[I,:,:]) area = pss.insert_shape_into_mesh(pss.mesh_Shps[I,:,:],x,y) ii+= 1 J += 1 # J is now the total number of particles inserted placed_part_area.append(area) # Update the list of areas xcoords.append(x) ycoords.append(y) radii.append(np.amax(part_radii[I])) I_shape.append(I) J_shape.append(J) elif vol_placed_frac < vfraclimit*vol_frac: #elif J%2 == 0: if ii >= MM: ii = 0 I = random.randint(nmin,nmax) # Generate a random number to randomly select one of the generated shapes, to be tried for this loop fail = 1
A_ = [] # Generate empty lists to store the area xc = [] # x coord yc = [] # y coord I_ = [] # Library index J_ = [] # shape number of each placed particle vf_pld = 0 # Volume Fraction of material inserted into the mesh so far J = 0 old_vfrac = 0. try: # Begin loop placing grains in. while vf_pld < vol_frac: # Keep attempting to add particles until the required volume fraction is achieved I = random.randint(0,n-1) # Generate a random index to randomly select a particle from the 'library' fail = 1 while fail == 1: # Whilst fail == 1 continue to try to generate a coordinate x,y,fail = pss.gen_coord(pss.mesh_Shps[I,:,:]) # Function generates a coordinate where the placed shape does not overlap with any placed so far area = pss.insert_shape_into_mesh(pss.mesh_Shps[I,:,:],x,y) J += 1 # pss.place_shape(pss.mesh_Shps[0,:,:],J,I,M) # This function allows you to place a shape in AND specify its material. However it overwrites previous placings A_.append(area) # Save the area xc.append(x) # Save the coords of that particle yc.append(y) J_.append(J) # Save the particle number I_.append(I) # Save the library index vf_pld = np.sum(A_)/(pss.meshx*pss.meshy) # update the volume fraction if vf_pld == old_vfrac: print '##########~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##########' print '# volume fraction no longer increasing. Break here #' print '##########~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##########' break