Skip to content

Commit

Permalink
removed _tmpx,_tmpy,_tmpz properties and added appropriate num_output…
Browse files Browse the repository at this point in the history
…s to funcs

stepping,gradient functions now only set the appropriate dimension properties instead of all 3
*Reverted* pickling of particle_array to pickle all properties since it broke parallel runs (elliptical_drop)
  • Loading branch information
pankajp committed May 8, 2011
1 parent 8faebfd commit c8e0e36
Show file tree
Hide file tree
Showing 26 changed files with 148 additions and 90 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ epydoc :
doc :
cd docs; make html

develop : $(DIRS)
develop :
python setup.py develop

install : $(DIRS)
install :
python setup.py install

clang :
Expand Down
13 changes: 6 additions & 7 deletions source/pysph/base/particle_array.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,12 @@ cdef class ParticleArray:
default_values = {}

for prop, arr in self.properties.iteritems():
if not prop.startswith('_'):
pinfo = {}
pinfo['name'] = prop
pinfo['type'] = arr.get_c_type()
pinfo['data'] = arr.get_npy_array()
pinfo['default'] = self.default_values[prop]
props[prop] = pinfo
pinfo = {}
pinfo['name'] = prop
pinfo['type'] = arr.get_c_type()
pinfo['data'] = arr.get_npy_array()
pinfo['default'] = self.default_values[prop]
props[prop] = pinfo

d['properties'] = props

Expand Down
3 changes: 1 addition & 2 deletions source/pysph/base/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ def get_particle_array(cl_precision="double", **props):

default_props = {'x':0.0, 'y':0.0, 'z':0.0, 'u':0.0, 'v':0.0 ,
'w':0.0, 'm':1.0, 'h':1.0, 'p':0.0,'e':0.0,
'rho':1.0, 'cs':0.0, '_tmpx':0.0,
'_tmpy':0.0, '_tmpz':0.0}
'rho':1.0, 'cs':0.0}

#Add the properties requested

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
# make sure the sending data defines the underscored variables
assert pa.properties.has_key('_rho')
assert pa.properties.has_key('_p')
assert pa.properties.has_key('_tmpx')
assert pa.properties.has_key('_tmpy')
assert pa.properties.has_key('_tmpz')

comm.send(obj=pa, dest=1)

Expand All @@ -45,9 +42,6 @@
# make sure that the underscored variables are not there
assert not pa2.properties.has_key('_rho')
assert not pa2.properties.has_key('_p')
assert not pa2.properties.has_key('_tmpx')
assert not pa2.properties.has_key('_tmpy')
assert not pa2.properties.has_key('_tmpz')

# now append the received array to the local array
pa.append_parray(pa2)
Expand Down
4 changes: 4 additions & 0 deletions source/pysph/parallel/tests/test_parallel_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def test_parallel_cell_check3(self):
def test_share_data(self):
for i in range(1,6):
run_mpi_script('share_data.py', i)

def test_particle_array_pickling(self):
for i in range(2,3):
run_mpi_script('particle_array_pickling.py', i)


#for filename in tests:
Expand Down
2 changes: 1 addition & 1 deletion source/pysph/solver/fluid_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def setup_solver(self):
self.add_operation(SPHIntegration(
sph.MomentumEquation.withargs(alpha=0.01, beta=0.0, hks=False),
from_types=[Fluids], on_types=[Fluids],
updates=['u','v'],
updates=['u','v','w'],
id='mom')
)

Expand Down
2 changes: 0 additions & 2 deletions source/pysph/solver/integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ def __init__(self, particles=None, calcs=[], pcalcs = []):

self.rupdate_list = []

self.step_props = '_tmpx', '_tmpy', '_tmpz'

def set_rupdate_list(self):
for i in range(len(self.particles.arrays)):
self.rupdate_list.append([])
Expand Down
7 changes: 3 additions & 4 deletions source/pysph/solver/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def add_operation_step(self, types, xsph=False, eps=0.5):
id = 'step'

self.add_operation(SPHIntegration(
sph.PositionStepping, on_types=types, updates=updates, id=id,
kernel=kernel)
sph.PositionStepping.withargs(dim=self.dim), on_types=types,
updates=updates, id=id, kernel=kernel)
)

def add_operation_xsph(self, eps, hks=False):
Expand Down Expand Up @@ -171,13 +171,12 @@ def add_operation_xsph(self, eps, hks=False):
assert self.operation_dict.has_key('step'), err

types = self.operation_dict['step'].on_types
from_types = self.operation_dict['step'].from_types
updates = self.operation_dict['step'].updates


self.add_operation(SPHIntegration(

sph.XSPHCorrection.withargs(eps=eps, hks=hks), from_types=from_types,
sph.XSPHCorrection.withargs(eps=eps, hks=hks, dim=self.dim), from_types=types,
on_types=types, updates=updates, id=id, kernel=self.default_kernel)

)
Expand Down
3 changes: 3 additions & 0 deletions source/pysph/sph/funcs/adke_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ cdef class ADKEPilotRho(CSPHFunctionParticle):

self.cl_kernel_src_file = "adke_funcs.cl"
self.cl_kernel_function_name = "ADKEPilotRho"
self.num_outputs = 1

def set_src_dst_reads(self):

Expand Down Expand Up @@ -94,6 +95,7 @@ cdef class ADKESmoothingUpdate(SPHFunction):

self.cl_kernel_src_file = "adke_funcs.cl"
self.cl_kernel_function_name = "ADKESmoothingUpdate"
self.num_outputs = 1

cpdef setup_arrays(self):
"""
Expand Down Expand Up @@ -237,6 +239,7 @@ cdef class ADKEConductionCoeffUpdate(SPHFunction):
self.cl_kernel_src_file = "adke_funcs.cl"

self.cl_kernel_function_name = "ADKEConductionCoeffUpdate"
self.num_outputs = 1

def set_src_dst_reads(self):
self.src_reads = []
Expand Down
2 changes: 2 additions & 0 deletions source/pysph/sph/funcs/arithmetic_funcs.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ cdef class PropertyGet(SPHFunction):
cdef class PropertyAdd(SPHFunction):
cdef list prop_names, d_props
cdef int num_props
cdef public double constant

cdef class PropertyNeg(SPHFunction):
cdef list prop_names, d_props

cdef class PropertyMul(SPHFunction):
cdef list prop_names, d_props
cdef int num_props
cdef public double constant

cdef class PropertyInv(SPHFunction):
cdef list prop_names, d_props
Expand Down
16 changes: 10 additions & 6 deletions source/pysph/sph/funcs/arithmetic_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ cdef class PropertyGet(SPHFunction):
cdef class PropertyAdd(SPHFunction):
""" function to add property arrays (any number of arrays) """
def __init__(self, ParticleArray source, ParticleArray dest=None,
prop_names=['rho'], **kwargs):
prop_names=['rho'], constant=0.0, **kwargs):
""" Constructor for SPH
Parameters:
-----------
source -- The source particle array
dest -- The destination particle array
prop_names -- The properties to get the sum of
constant -- a constant value to add to the result
"""
self.prop_names = prop_names
self.constant = constant
SPHFunction.__init__(self, source, dest, setup_arrays=True)
self.num_outputs = 1
self.id = 'property_add'
Expand All @@ -55,7 +57,7 @@ cdef class PropertyAdd(SPHFunction):
#Setup the basic properties like m, x rho etc.
SPHFunction.setup_arrays(self)
self.d_props = [self.dest.get_carray(i) for i in self.prop_names]
self.num_props = len(self.prop_names)
self.num_props = len(self.d_props)

cpdef eval(self, KernelBase kernel, DoubleArray output1,
DoubleArray output2, DoubleArray output3):
Expand All @@ -67,7 +69,7 @@ cdef class PropertyAdd(SPHFunction):
for n in range(1, self.num_props):
arr = self.d_props[n]
for i in range(np):
output1.data[i] += arr.data[i]
output1.data[i] += arr.data[i] + self.constant

cdef class PropertyNeg(SPHFunction):
""" function to return the negative of upto 3 particle arrays """
Expand Down Expand Up @@ -105,16 +107,18 @@ cdef class PropertyNeg(SPHFunction):
cdef class PropertyMul(SPHFunction):
""" function to get product of property arrays (any number of arrays) """
def __init__(self, ParticleArray source, ParticleArray dest=None,
prop_names=['rho'], **kwargs):
prop_names=['rho'], constant=0.0, **kwargs):
""" Constructor for SPH
Parameters:
-----------
source -- The source particle array.
dest -- The destination particle array.
prop_names -- The properties to get product of
constant -- a constant value to multiply to the result
"""
self.prop_names = prop_names
self.constant = constant
SPHFunction.__init__(self, source, dest, setup_arrays=True)
self.num_outputs = 1
self.id = 'property_mul'
Expand All @@ -123,7 +127,7 @@ cdef class PropertyMul(SPHFunction):
#Setup the basic properties like m, x rho etc.
SPHFunction.setup_arrays(self)
self.d_props = [self.dest.get_carray(i) for i in self.prop_names]
self.num_props = len(self.prop_names)
self.num_props = len(self.d_props)

cpdef eval(self, KernelBase kernel, DoubleArray output1,
DoubleArray output2, DoubleArray output3):
Expand All @@ -135,7 +139,7 @@ cdef class PropertyMul(SPHFunction):
for n in range(1, self.num_props):
arr = self.d_props[n]
for i in range(np):
output1.data[i] *= arr.data[i]
output1.data[i] *= arr.data[i] * self.constant

cdef class PropertyInv(SPHFunction):
""" function to return the inverse of upto 3 particle arrays """
Expand Down
2 changes: 2 additions & 0 deletions source/pysph/sph/funcs/basic_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cdef class SPH(CSPHFunctionParticle):

self.cl_kernel_src_file = "basic_funcs.clt"
self.cl_kernel_function_name = "SPH"
self.num_outputs = 1

def set_src_dst_reads(self):
self.src_reads = []
Expand Down Expand Up @@ -337,6 +338,7 @@ cdef class SPHLaplacian(SPHFunctionParticle):

self.cl_kernel_src_file = "basic_funcs.cl"
self.cl_kernel_function_name = "SPHLaplacian"
self.num_outputs = 1

def set_src_dst_reads(self):
self.src_reads = []
Expand Down
2 changes: 2 additions & 0 deletions source/pysph/sph/funcs/density_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cdef class SPHRho(CSPHFunctionParticle):

self.cl_kernel_src_file = "density_funcs.clt"
self.cl_kernel_function_name = "SPHRho"
self.num_outputs = 1

def set_src_dst_reads(self):
self.src_reads = []
Expand Down Expand Up @@ -98,6 +99,7 @@ cdef class SPHDensityRate(SPHFunctionParticle):

self.cl_kernel_src_file = "density_funcs.cl"
self.cl_kernel_function_name = "SPHDensityRate"
self.num_outputs = 1

def set_src_dst_reads(self):
self.src_reads = []
Expand Down
4 changes: 4 additions & 0 deletions source/pysph/sph/funcs/energy_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cdef class EnergyEquationNoVisc(SPHFunctionParticle):

self.cl_kernel_src_file = "energy_funcs.cl"
self.cl_kernel_function_name = "EnergyEquationNoVisc"
self.num_outputs = 1

def set_src_dst_reads(self):
self.src_reads = []
Expand Down Expand Up @@ -128,6 +129,7 @@ cdef class EnergyEquationAVisc(SPHFunctionParticle):

self.cl_kernel_src_file = "energy_funcs.cl"
self.cl_kernel_function_name = "EnergyEquationAVisc"
self.num_outputs = 1

def set_src_dst_reads(self):
self.src_reads = []
Expand Down Expand Up @@ -251,6 +253,7 @@ cdef class EnergyEquation(SPHFunctionParticle):

self.cl_kernel_src_file = "energy_funcs.cl"
self.cl_kernel_function_name = "EnergyEquationWithVisc"
self.num_outputs = 1

def set_src_dst_reads(self):
self.src_reads = []
Expand Down Expand Up @@ -400,6 +403,7 @@ cdef class ArtificialHeat(SPHFunctionParticle):

self.cl_kernel_src_file = "energy_funcs.cl"
self.cl_kernel_function_name = "ArtificialHeat"
self.num_outputs = 1

def set_src_dst_reads(self):
self.src_reads = ['x','y','z','h','m','rho','e,','u','v','w','cs','q']
Expand Down
2 changes: 2 additions & 0 deletions source/pysph/sph/funcs/eos_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cdef class IdealGasEquation(SPHFunction):

self.cl_kernel_src_file = "eos_funcs.cl"
self.cl_kernel_function_name = "IdealGasEquation"
self.num_outputs = 2

def set_src_dst_reads(self):
self.src_reads = []
Expand Down Expand Up @@ -93,6 +94,7 @@ cdef class TaitEquation(SPHFunction):
self.tag = "state"

self.cl_kernel_src_file = "eos_funcs.cl"
self.num_outputs = 2

def set_src_dst_reads(self):
self.src_reads = []
Expand Down
2 changes: 2 additions & 0 deletions source/pysph/sph/funcs/external_force.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ cdef class MoveCircleX(SPHFunction):

self.id = 'circlex'
self.tag = "position"
self.num_outputs = 2

def set_src_dst_reads(self):
pass
Expand Down Expand Up @@ -144,6 +145,7 @@ cdef class MoveCircleY(SPHFunction):

self.id = 'circley'
self.tag = "position"
self.num_outputs = 2

def set_src_dst_reads(self):
pass
Expand Down
36 changes: 26 additions & 10 deletions source/pysph/sph/funcs/position_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cdef class PositionStepping(SPHFunction):

#Defined in the .pxd file
def __init__(self, ParticleArray source, ParticleArray dest,
bint setup_arrays=True):
bint setup_arrays=True, int dim=3):

SPHFunction.__init__(self, source, dest, setup_arrays)

Expand All @@ -21,12 +21,13 @@ cdef class PositionStepping(SPHFunction):

self.cl_kernel_src_file = "position_funcs.clt"
self.cl_kernel_function_name = "PositionStepping"
self.num_outputs = dim

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.dst_reads.extend( ['u','v','w'] )
self.dst_reads.extend( ['u','v','w'][:self.num_outputs] )

cpdef eval(self, KernelBase kernel, DoubleArray output1,
DoubleArray output2, DoubleArray output3):
Expand All @@ -35,14 +36,29 @@ cdef class PositionStepping(SPHFunction):

self.setup_iter_data()
cdef size_t np = self.dest.get_number_of_particles()

for i in range(np):
if tag_arr.data[i] == LocalReal:
output1[i] = self.d_u.data[i]
output2[i] = self.d_v.data[i]
output3[i] = self.d_w.data[i]
else:
output1[i] = output2[i] = output3[i] = 0

if self.num_outputs == 3:
for i in range(np):
if tag_arr.data[i] == LocalReal:
output1.data[i] += self.d_u.data[i]
output2.data[i] += self.d_v.data[i]
output3.data[i] += self.d_w.data[i]
else:
output1.data[i] = output2.data[i] = output3.data[i] = 0
elif self.num_outputs == 2:
for i in range(np):
if tag_arr.data[i] == LocalReal:
output1.data[i] += self.d_u.data[i]
output2.data[i] += self.d_v.data[i]
else:
output1.data[i] = output2.data[i] = 0
elif self.num_outputs == 1:
for i in range(np):
if tag_arr.data[i] == LocalReal:
output1.data[i] += self.d_u.data[i]
else:
output1.data[i] = 0


def _set_extra_cl_args(self):
pass
Expand Down
Loading

0 comments on commit c8e0e36

Please sign in to comment.