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)
def cleanup(self, del_code, ignore_code, part_dens): pos_cl = CLReal4() info_cl = CLInt() shp0_cl = CLScalar(0) shp1_cl = CLScalar(0) shp2_cl = CLScalar(0) minx_cl = CLScalar(0.) miny_cl = CLScalar(0.) minz_cl = CLScalar(0.) maxx_cl = CLScalar(0.) maxy_cl = CLScalar(0.) maxz_cl = CLScalar(0.) is_filled_domain_cl = CLScalar(0) del_code_cl = CLScalar(del_code) ignore_code_cl = CLScalar(ignore_code) vol_cl = CLReal() pos_cl.value = self.pos info_cl.value = self.info spc_cl = CLScalar(0.) offset_cl = CLScalar(0.) offset_inner_cl = CLScalar(0.) partrad_cl = CLScalar(math.pow((1./part_dens)*3./(4.*math.pi), 1./3.)) krn = CLTemplateKernel(pre=_GET_DIST_GRAD_SRC, src=_CLEANUP_SRC) krn.pos = pos_cl krn.info = info_cl krn.shp0 = shp0_cl krn.shp1 = shp1_cl krn.shp2 = shp2_cl krn.minx = minx_cl krn.miny = miny_cl krn.minz = minz_cl krn.maxx = maxx_cl krn.maxy = maxy_cl krn.maxz = maxz_cl krn.is_filled_domain = is_filled_domain_cl krn.del_code = del_code_cl krn.ignore_code = ignore_code_cl krn.vol = vol_cl krn.spc = spc_cl krn.offset = offset_cl krn.offset_inner = offset_inner_cl krn.partrad = partrad_cl krn.compile() for domain in self.domains: if domain.mat_type == del_code: continue if isinstance(domain, SolidBound): is_filled_domain_cl.value = 1 else: is_filled_domain_cl.value = 0 minx_cl.value = domain.voldat.orig[0] miny_cl.value = domain.voldat.orig[1] minz_cl.value = domain.voldat.orig[2] maxx_cl.value = domain.voldat.max[0] maxy_cl.value = domain.voldat.max[1] maxz_cl.value = domain.voldat.max[2] shp0_cl.value = domain.voldat._voxels.shape[2] shp1_cl.value = domain.voldat._voxels.shape[1] shp2_cl.value = domain.voldat._voxels.shape[0] vol_cl.value = domain.voldat._voxels.value spc_cl.value = domain.voldat.spc offset_cl.value = 0. offset_inner_cl.value = -pow(10., 38) if isinstance(domain, SolidBound): offset_cl.value = domain.offset + domain.thick offset_inner_cl.value = domain.offset if isinstance(domain, FluidDomain): offset_cl.value = domain.offset krn() self.pos = pos_cl.value self.info = info_cl.value