def setup_in_volume(volume, count, h, spc=1., orig=(0.,0.,0.), offset=0., offset_inner=None, steps=100, fact=0.0001, maxneighs=1000, radius=0.): max_x_cl = CLScalar(volume.shape[0]*spc) max_y_cl = CLScalar(volume.shape[1]*spc) max_z_cl = CLScalar(volume.shape[2]*spc) particles_cl = CLReal4() oi = None if not offset_inner == None: oi = offset_inner - radius particles_cl.value = rand_particles_in_volume(volume, count, spc=spc, orig=(0.,0.,0.), offset=offset + radius, offset_inner=oi) maxneighs_cl = CLScalar(maxneighs) volume.shape = (volume.shape[0],volume.shape[1],volume.shape[2],1) vol_cl = CLReal() vol_cl.value = volume neighsearch = Neighsearch(particles_cl, h=h, maxneighs=int(maxneighs_cl.value)) neighsearch.search() h_cl = CLScalar(h) fact_cl = CLScalar(fact) vol_shp0_cl = CLScalar(volume.shape[0]) vol_shp1_cl = CLScalar(volume.shape[1]) vol_shp2_cl = CLScalar(volume.shape[2]) offset_cl = CLScalar(offset) if offset_inner == None: offset_inner = -pow(10., 38) offset_inner_cl = CLScalar(offset_inner) print "offsets: ", offset_cl, offset_inner_cl gradient_cl = CLReal4() gradient_cl.value = gradient_field(volume) kern = CLTemplateKernel(src=_RELAXPART_SRC, pre=_GET_DIST_GRAD_SRC) kern.pos = particles_cl kern.h = h_cl kern.maxneighs = maxneighs_cl kern.neighbors = neighsearch.neighbors kern.fact = fact_cl kern.volume = vol_cl kern.spacing = CLScalar(spc) kern.vol_shp0 = vol_shp0_cl kern.vol_shp1 = vol_shp1_cl kern.vol_shp2 = vol_shp2_cl kern.offset = offset_cl kern.offset_inner = offset_inner_cl kern.gradient = gradient_cl kern.max_x = max_x_cl kern.max_y = max_y_cl kern.max_z = max_z_cl kern.compile() print 'Particle initialization' for i in range(steps): neighsearch.search() kern() kern.finish() print 'Step', i+1, 'of', steps ret = particles_cl.value ret[:,0] += orig[0] ret[:,1] += orig[1] ret[:,2] += orig[2] return ret
def setup_with_particles(particles_in, volume, count, h, spc=1., orig=(0.,0.,0.), offset=0., offset_inner=None, steps=100, fact=0.0001, maxneighs=300): max_x_cl = CLScalar(volume.shape[0]*spc + orig[0]) max_y_cl = CLScalar(volume.shape[1]*spc + orig[1]) max_z_cl = CLScalar(volume.shape[2]*spc + orig[2]) min_x_cl = CLScalar(orig[0]) min_y_cl = CLScalar(orig[1]) min_z_cl = CLScalar(orig[2]) maxneighs_cl = CLScalar(maxneighs) parts_new = rand_particles_in_volume(volume, count, spc=spc, orig=orig, offset=offset, offset_inner=offset_inner) particles_cl = CLReal4() particles_cl.value = np.vstack((parts_new, particles_in)) flag_cl = CLChar() flag_cl.value = np.vstack((np.zeros((len(parts_new),1)), np.ones((len(particles_in),1))))# 1->boundary particle, 0->movable particle grp = Syncgroup(particles_cl, flag_cl) neighsearch = Neighsearch(particles_cl, h=h, maxneighs=int(maxneighs_cl.value), group=grp) neighsearch.search() h_cl = CLScalar(h) fact_cl = CLScalar(fact) kern = CLTemplateKernel(src=_RELAXPART_WITH_PART_SRC) kern.pos = particles_cl kern.flag = flag_cl kern.h = h_cl kern.maxneighs = maxneighs_cl kern.neighbors = neighsearch.neighbors kern.fact = fact_cl kern.max_x = max_x_cl kern.max_y = max_y_cl kern.max_z = max_z_cl kern.min_x = min_x_cl kern.min_y = min_y_cl kern.min_z = min_z_cl kern.compile() print 'Particle initialization' for i in range(steps): neighsearch.search() kern() print 'Step', i+1, 'of', steps parts = particles_cl.value ret = [] flags = flag_cl.value for i in range(len(parts)): if flags[i,0] == 0: ret.append(parts[i]) return np.array(ret)