コード例 #1
0
ファイル: scene.py プロジェクト: hagisgit/pyclsph
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
コード例 #2
0
ファイル: test_mpl.py プロジェクト: hagisgit/pyclsph
@author: Hagen
"""

# import useful modules
from matplotlib import pyplot

from meshtools import load_vtk_polydata, voxelize
from numcl.tools import gradient_field
import numpy as np

tri, vert = load_vtk_polydata('/Users/Hagen/Code/Python/sphPy/Test.vtk')

vol = voxelize(tri, vert, res=10, refine=1, framewidth=0.1)
vol.shape = (vol.shape[0],vol.shape[1],vol.shape[2],1)
grad = gradient_field(vol)


for i in range(1):
    theslice = i

    x = np.zeros(vol.shape[2])
    y = np.zeros(vol.shape[1])
    u = np.zeros((grad.shape[1],grad.shape[2]))
    v = np.zeros((grad.shape[1],grad.shape[2]))

    for n in range(len(x)):
        x[n] = n
    for n in range(len(y)):
        y[n] = n