Skip to content

Commit

Permalink
add _tmp in calc if insufficient arguments are supplied to calc.sph()…
Browse files Browse the repository at this point in the history
… in case of funcs which operate on all 3 output arrays

and replaced raising error for such cases with a warning log
  • Loading branch information
pankajp committed May 8, 2011
1 parent c8e0e36 commit e8bbc4f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
10 changes: 5 additions & 5 deletions source/pysph/sph/funcs/arithmetic_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cdef class PropertyGet(SPHFunction):
dest -- The destination particle array
prop_names -- The properties to get (upto 3 particle arrays)
"""
self.prop_names = prop_names
self.prop_names = list(prop_names)
SPHFunction.__init__(self, source, dest, setup_arrays=True)
self.num_outputs = len(prop_names)
self.id = 'property_get'
Expand Down Expand Up @@ -47,7 +47,7 @@ cdef class PropertyAdd(SPHFunction):
prop_names -- The properties to get the sum of
constant -- a constant value to add to the result
"""
self.prop_names = prop_names
self.prop_names = list(prop_names)
self.constant = constant
SPHFunction.__init__(self, source, dest, setup_arrays=True)
self.num_outputs = 1
Expand Down Expand Up @@ -83,7 +83,7 @@ cdef class PropertyNeg(SPHFunction):
dest -- The destination particle array.
prop_names -- The properties to get the inverse of (upto 3)
"""
self.prop_names = prop_names
self.prop_names = list(prop_names)
SPHFunction.__init__(self, source, dest, setup_arrays=True)
self.num_outputs = len(prop_names)
self.id = 'property_neg'
Expand Down Expand Up @@ -117,7 +117,7 @@ cdef class PropertyMul(SPHFunction):
prop_names -- The properties to get product of
constant -- a constant value to multiply to the result
"""
self.prop_names = prop_names
self.prop_names = list(prop_names)
self.constant = constant
SPHFunction.__init__(self, source, dest, setup_arrays=True)
self.num_outputs = 1
Expand Down Expand Up @@ -153,7 +153,7 @@ cdef class PropertyInv(SPHFunction):
dest -- The destination particle array.
prop_names -- The properties to get inverse of (upto 3)
"""
self.prop_names = prop_names
self.prop_names = list(prop_names)
SPHFunction.__init__(self, source, dest, setup_arrays=True)
self.num_outputs = len(prop_names)
self.id = 'property_inv'
Expand Down
41 changes: 26 additions & 15 deletions source/pysph/sph/sph_calc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ cdef class SPHCalc:
msg = 'SPHFunction.source not same as'
msg += ' SPHCalc.sources[%d]'%(i)
raise ValueError, msg
if funcs[i].num_outputs > len(self.updates):
raise ValueError, ('Number of updates not same as num_outputs'
'; required %d, got %d %s for func %s'%(funcs[i].num_outputs,
len(self.updates), self.updates, funcs[i]))
if funcs[i].num_outputs != len(self.updates):
logger.warn('Number of updates not same as num_outputs; '
'required %d, got %d %s for func %s'%(
funcs[i].num_outputs, len(self.updates),
self.updates, funcs[i]))
# not valid for SPHFunction
#if funcs[i].dest != self.dest:
# msg = 'SPHFunction.dest not same as'
Expand Down Expand Up @@ -216,24 +217,34 @@ cdef class SPHCalc:

func = self.funcs[0]

# Add temporary array in case of fewer arguments to sph()
self.dest.add_property(dict(name='_tmp'))

self.src_reads = func.src_reads
self.dst_reads = func.dst_reads

cpdef sph(self, str output_array1=None, str output_array2=None,
str output_array3=None, bint exclude_self=False):
"""
"""
if output_array1 is None: output_array1 = '_tmpx'
if output_array2 is None: output_array2 = '_tmpy'
if output_array3 is None: output_array3 = '_tmpz'

cdef DoubleArray output1 = self.dest.get_carray(output_array1)
cdef DoubleArray output2 = self.dest.get_carray(output_array2)
cdef DoubleArray output3 = self.dest.get_carray(output_array3)

if output1 is not None: self.reset_output_array(output1)
if output2 is not None: self.reset_output_array(output2)
if output3 is not None: self.reset_output_array(output3)
cdef DoubleArray output1, output2, output3
if output_array1 is None:
output1 = self.dest.get_carray('_tmp')
else:
output1 = self.dest.get_carray(output_array1)
self.reset_output_array(output1)

if output_array2 is None:
output2 = self.dest.get_carray('_tmp')
else:
output2 = self.dest.get_carray(output_array2)
self.reset_output_array(output2)

if output_array3 is None:
output3 = self.dest.get_carray('_tmp')
else:
output3 = self.dest.get_carray(output_array3)
self.reset_output_array(output3)

self.sph_array(output1, output2, output3, exclude_self)

Expand Down
4 changes: 2 additions & 2 deletions source/pysph/sph/tests/test_boundary_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setUp(self):
rhof = numpy.ones_like(xf)

self.fluid = base.get_particle_array(x=xf, y=yf, h=hf, m=mf, rho=rhof,
cs=cs, tmpx=mf, tmpy=mf, tmpz=mf,
cs=cs, ax=mf, ay=mf, az=mf,
name='fluid', type=Fluid)


Expand Down Expand Up @@ -113,7 +113,7 @@ def test_force(self):

self.particles.update()

calc.sph('tmpx', 'tmpy', 'tmpz')
calc.sph('ax', 'ay', 'az')

force = fluid.tmpy

Expand Down

0 comments on commit e8bbc4f

Please sign in to comment.