#pss.place_shape(pss.mesh_Shps[0,:,:],lx,0,1,UC,LX=lx,LY=ly) #pss.place_shape(pss.mesh_Shps[0,:,:],0,ly,1,UC,LX=lx,LY=ly) #pss.place_shape(pss.mesh_Shps[0,:,:],lx,ly,1,UC,LX=lx,LY=ly) plt.figure() plt.imshow(UC[0,:,:],interpolation='nearest',cmap='binary') plt.imshow(UC[1,:,:],interpolation='nearest',cmap='binary',alpha=.5) plt.imshow(UC[2,:,:],interpolation='nearest',cmap='binary',alpha=.5) plt.imshow(UC[3,:,:],interpolation='nearest',cmap='binary',alpha=.5) Ms,xcoords,ycoords,radii = pss.copypasteUC(UC,UCX,UCY,RAD,MATS) Ms = pss.mat_assignment(mats,xcoords,ycoords,radii) #plt.figure() #plt.imshow(pss.materials[0,:,:],interpolation='nearest',cmap='binary') #plt.imshow(pss.materials[1,:,:],interpolation='nearest',cmap='binary',alpha=.5) #plt.imshow(pss.materials[2,:,:],interpolation='nearest',cmap='binary',alpha=.5) #plt.imshow(pss.materials[3,:,:],interpolation='nearest',cmap='binary',alpha=.5) #plt.show() S = float(np.sum(UC)-4*3)#There are 4 particles and 3 cells overlap per particle print "Approximate Volume Fraction = {:3.1f}".format(S/float(lx*ly)) A,B = pss.part_distance(xcoords,ycoords,radii,Ms,plot=True) xcoords *= GRIDSPC ycoords *= GRIDSPC radii *= GRIDSPC pss.save_spherical_parts(xcoords,ycoords,radii,Ms,A)
#pss.place_shape(pss.mesh_Shps[0,:,:],48,32-16,4,UC,LX=lx,LY=ly) #pss.place_shape(pss.mesh_Shps[0,:,:],32,32+20,1,UC,LX=lx,LY=ly) #pss.place_shape(pss.mesh_Shps[0,:,:],lx,0,1,UC,LX=lx,LY=ly) #pss.place_shape(pss.mesh_Shps[0,:,:],0,ly,1,UC,LX=lx,LY=ly) #pss.place_shape(pss.mesh_Shps[0,:,:],lx,ly,1,UC,LX=lx,LY=ly) plt.figure() plt.imshow(UC[0, :, :], interpolation='nearest', cmap='binary') plt.imshow(UC[1, :, :], interpolation='nearest', cmap='binary', alpha=.5) plt.imshow(UC[2, :, :], interpolation='nearest', cmap='binary', alpha=.5) plt.imshow(UC[3, :, :], interpolation='nearest', cmap='binary', alpha=.5) Ms, xcoords, ycoords, radii = pss.copypasteUC(UC, UCX, UCY, RAD, MATS) Ms = pss.mat_assignment(mats, xcoords, ycoords, radii) #plt.figure() #plt.imshow(pss.materials[0,:,:],interpolation='nearest',cmap='binary') #plt.imshow(pss.materials[1,:,:],interpolation='nearest',cmap='binary',alpha=.5) #plt.imshow(pss.materials[2,:,:],interpolation='nearest',cmap='binary',alpha=.5) #plt.imshow(pss.materials[3,:,:],interpolation='nearest',cmap='binary',alpha=.5) #plt.show() S = float(np.sum(UC) - 4 * 3) #There are 4 particles and 3 cells overlap per particle print "Approximate Volume Fraction = {:3.1f}".format(S / float(lx * ly)) A, B = pss.part_distance(xcoords, ycoords, radii, Ms, plot=True) xcoords *= GRIDSPC ycoords *= GRIDSPC radii *= GRIDSPC
xcr = np.array(xcoords) ycr = np.array(ycoords) radii = np.array(radii) XINT = np.copy(xcr) # Coordinates and radii are in units of 'cells' up to here YINT = np.copy( ycr ) # This keeps a copy of these before they're converted to physical units xcr = xcr.astype(float) # Convert to floats ycr = ycr.astype(float) radii = radii.astype(float) xcr *= GRIDSPC # Convert to physical units ycr *= GRIDSPC MAT = pss.mat_assignment(pss.mats, xcr, ycr) # Assign materials to the particles radii *= GRIDSPC #pss.save_spherical_parts(xcr,ycr,radii,MAT,A,fname='coords.txt') # Save particle coordinates, radii and material number as a txt file with file name fname # When fname is not 'meso' A doe snot need to be anything and can just be zero as it is not used pss.save_particle_mesh( I_shape, XINT, YINT, MAT, J ) # Save full mesh as a meso_m.iSALE file. NB This uses the integer coords we had before print "total particles placed: {}".format(J) placed_part_area = np.array(placed_part_area) vol_frac_calc = np.sum(placed_part_area) / (pss.meshx * pss.meshy) if abs(vol_frac_calc - pss.vol_frac) <= 0.02: print "GREAT SUCCESS! Volume Fraction = {:3.3f}%".format(vol_frac_calc *
w *= sc h *= sc xc *= sc * GRIDSPC yc *= sc * GRIDSPC rc *= sc * GRIDSPC # Calculate number of occurences No = X_cells * Y_cells / (w * h) Nx = int(X_cells / w) Ny = int(Y_cells / h) w *= GRIDSPC h *= GRIDSPC X = [] Y = [] for i in range(Nx): for j in range(Ny): X.append(xc + i * w) Y.append(yc + j * h) X = np.array(X) Y = np.array(Y) N = np.size(X) radii = np.full((N), r) MAT = pss.mat_assignment(mats, X, Y, radii) A, B = pss.part_distance(X, Y, radii, MAT, plot=True) pss.save_spherical_parts(X, Y, radii, MAT, A) pss.view_mesoiSALE(filepath='meso_A-{:3.4f}.iSALE'.format(A))
""" XY = np.column_stack((xcr,ycr)) mytree = scsp.cKDTree(XY,leafsize=100) for item in XY: print mytree.query(item, k=np.size(mats)+1, distance_upper_bound=pss.cppr_max*3) """ xcr *= GRIDSPC ycr *= GRIDSPC zcr *= GRIDSPC radii *= GRIDSPC MAT = pss.mat_assignment(mats,xcr,ycr) DMY = np.zeros_like(xcoords) A,B = pss.part_distance(xcr,ycr,radii,MAT,False) print "The Contacts Measure, A = {}".format(A) print "Avg Contacts Between the Same Materials, B = {}".format(B) print 'Total contacts between same materials = {}, Total particles = {}'.format(B*J,J) ALL = np.column_stack((MAT,xcr,ycr,radii)) pss.populate_materials(I_shape,XINT,YINT,MAT,J,TRACERS=True,ON=J_shape) # Now populate the materials meshes (NB these are different to the 'mesh' and are pss.save_spherical_parts(xcr,ycr,radii,MAT,A) print 'save to meso_A-{:3.4f}.iSALE'.format(A) pss.save_general_mesh(tracers=True) A2, contact_matrix = pss.discrete_contacts_number(I_shape,XINT,YINT,J,J_shape) print '\n'
radii = radii.astype(float) angle = angle.astype(float) eccen2 = eccen2.astype(float) """ XY = np.column_stack((xcr,ycr)) mytree = scsp.cKDTree(XY,leafsize=100) for item in XY: print mytree.query(item, k=np.size(mats)+1, distance_upper_bound=pss.cppr_max*3) """ xcr *= GRIDSPC ycr *= GRIDSPC zcr *= GRIDSPC radii *= GRIDSPC MAT = pss.mat_assignment(mats, xcr, ycr) DMY = np.zeros_like(xcoords) A, B = pss.part_distance(xcr, ycr, radii, MAT, False) print "The Contacts Measure, A = {}".format(A) print "Avg Contacts Between the Same Materials, B = {}".format(B) print 'Total contacts between same materials = {}, Total particles = {}'.format( B * J, J) ALL = np.column_stack((MAT, xcr, ycr, radii)) pss.populate_materials( I_shape, XINT, YINT, MAT, J, TRACERS=True, ON=J_shape ) # Now populate the materials meshes (NB these are different to the 'mesh' and are #pss.save_spherical_parts(xcr,ycr,radii,MAT,A) print 'save to meso_A-{:3.4f}.iSALE'.format(A) pss.save_general_mesh(tracers=True)
break old_vfrac = vf_pld print "volume fraction achieved so far: {:3.3f}%".format(vf_pld * 100) except KeyboardInterrupt: pass I_shape = np.array( I_) # Convert the lists of index, shape number, and coordinates to arrays J_shape = np.array(J_) xcSI = np.array(xc) ycSI = np.array(yc) xcSI *= GRIDSPC # Turn the coordinates into physical units ycSI *= GRIDSPC MAT = pss.mat_assignment( pss.mats[1:], xcSI, ycSI ) # Assign materials to the particles. This returns an array that is the same shape as xc, # and contains the optimum corresponding material number for each particle pss.populate_materials( I_, xc, yc, MAT, J ) # Now populate the materials meshes (NB these are different to the 'mesh' and are # the ones used in the actual iSALE input file) pss.fill_rectangle(0, 0, pss.meshx * GRIDSPC, pss.meshy * GRIDSPC, pss.mats[0]) # pySALESetup prioritises material placed sooner. So later things will NOT overwrite previous ones pss.save_general_mesh() # Save the mesh as meso_m.iSALE (default) plt.figure() # plot the resulting mesh. Skip this bit if you do not need to. for KK in range(pss.Ms): matter = np.copy(pss.materials[KK, :, :]) * (KK + 1) matter = np.ma.masked_where(matter == 0., matter)
print '# volume fraction no longer increasing. Break here #' print '##########~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##########' break old_vfrac = vf_pld print "volume fraction achieved so far: {:3.3f}%".format(vf_pld*100) except KeyboardInterrupt: pass I_shape = np.array(I_) # Convert the lists of index, shape number, and coordinates to arrays J_shape = np.array(J_) xcSI = np.array(xc) ycSI = np.array(yc) xcSI*= GRIDSPC # Turn the coordinates into physical units ycSI*= GRIDSPC MAT = pss.mat_assignment(pss.mats[1:],xcSI,ycSI) # Assign materials to the particles. This returns an array that is the same shape as xc, # and contains the optimum corresponding material number for each particle pss.populate_materials(I_,xc,yc,MAT,J) # Now populate the materials meshes (NB these are different to the 'mesh' and are # the ones used in the actual iSALE input file) pss.fill_rectangle(0,0,pss.meshx*GRIDSPC,pss.meshy*GRIDSPC,pss.mats[0]) # pySALESetup prioritises material placed sooner. So later things will NOT overwrite previous ones pss.save_general_mesh() # Save the mesh as meso_m.iSALE (default) plt.figure() # plot the resulting mesh. Skip this bit if you do not need to. for KK in range(pss.Ms): matter = np.copy(pss.materials[KK,:,:])*(KK+1) matter = np.ma.masked_where(matter==0.,matter) plt.imshow(matter, cmap='viridis',vmin=0,vmax=pss.Ms,interpolation='nearest') matter = np.copy(pss.materials[pss.Ms-1,:,:])*(pss.Ms)
xc*= sc*GRIDSPC yc*= sc*GRIDSPC rc*= sc*GRIDSPC # Calculate number of occurences No = X_cells*Y_cells/(w*h) Nx = int(X_cells/w) Ny = int(Y_cells/h) w *= GRIDSPC h *= GRIDSPC X = [] Y = [] for i in range(Nx): for j in range(Ny): X.append(xc+i*w) Y.append(yc+j*h) X = np.array(X) Y = np.array(Y) N = np.size(X) radii = np.full((N),r) MAT = pss.mat_assignment(mats,X,Y,radii) A,B = pss.part_distance(X,Y,radii,MAT,plot=True) pss.save_spherical_parts(X,Y,radii,MAT,A) pss.view_mesoiSALE(filepath='meso_A-{:3.4f}.iSALE'.format(A))
xcr = np.array(xcoords) ycr = np.array(ycoords) radii = np.array(radii) XINT = np.copy(xcr) # Coordinates and radii are in units of 'cells' up to here YINT = np.copy(ycr) # This keeps a copy of these before they're converted to physical units xcr = xcr.astype(float) # Convert to floats ycr = ycr.astype(float) radii = radii.astype(float) xcr *= GRIDSPC # Convert to physical units ycr *= GRIDSPC MAT = pss.mat_assignment(pss.mats,xcr,ycr) # Assign materials to the particles radii *= GRIDSPC #pss.save_spherical_parts(xcr,ycr,radii,MAT,A,fname='coords.txt') # Save particle coordinates, radii and material number as a txt file with file name fname # When fname is not 'meso' A doe snot need to be anything and can just be zero as it is not used pss.save_particle_mesh(I_shape,XINT,YINT,MAT,J) # Save full mesh as a meso_m.iSALE file. NB This uses the integer coords we had before print "total particles placed: {}".format(J) placed_part_area = np.array(placed_part_area) vol_frac_calc = np.sum(placed_part_area)/(pss.meshx*pss.meshy) if abs(vol_frac_calc - pss.vol_frac) <= 0.02: print "GREAT SUCCESS! Volume Fraction = {:3.3f}%".format(vol_frac_calc*100.) else: