Skip to content

Commit

Permalink
Merge pull request #196 from psnbaba/add_particle_fix
Browse files Browse the repository at this point in the history
added fix for #155
  • Loading branch information
prabhuramachandran committed Sep 4, 2019
2 parents df66164 + f66707f commit 9bfa8d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pysph/base/particle_array.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,17 @@ cdef class ParticleArray:
if len(particle_props) == 0:
return 0

# check if the input properties are valid.
prop = ''
for prop in particle_props:
self._check_property(prop)
if prop in self.stride.keys():
stride = self.stride[prop]
prop_len = len(particle_props[prop])
base_len = self.get_number_of_particles()
msg = 'Property %s length should be %d' % (prop, base_len * stride)
assert prop_len == base_len * stride, msg

if self.gpu is not None and self.backend is not 'cython':
gpu_particle_props = {}
for prop, ary in particle_props.items():
Expand All @@ -565,11 +576,6 @@ cdef class ParticleArray:
cdef int num_extra_particles, old_num_particles, new_num_particles
cdef numpy.ndarray s_arr, nparr

# check if the input properties are valid.
prop = ''
for prop in particle_props:
self._check_property(prop)

if len(prop) == 0:
num_extra_particles = 0
else:
Expand Down
9 changes: 9 additions & 0 deletions pysph/base/tests/test_particle_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ def test_add_particles(self):
self.assertEqual(check_array(p.y, [0, 1, 2, 3, 0, 0]), True)
self.assertEqual(check_array(p.z, [0, 0, 0, 0, 0, 0]), True)

# adding particles with tags
p = particle_array.ParticleArray(x={'data': x}, y={'data': y},
z={'data': z}, m={'data': m},
h={'data': h},
A={'data': A, 'stride': 3},
backend=self.backend)

self.assertRaises(AssertionError, p.add_particles, A=[5, 6, 7, 8])

def test_remove_tagged_particles(self):
x = [1, 2, 3, 4.]
y = [0., 1., 2., 3.]
Expand Down

0 comments on commit 9bfa8d6

Please sign in to comment.