Example #1
0
def remove_overlap_particles(fluid_parray, solid_parray, dx_solid, dim=3):
    """
    This function will take 2 particle arrays as input and will remove all
    the particles of the first particle array which are in the vicinity of
    the particles from second particle array. The function will remove all
    the particles within the dx_solid vicinity so some particles are removed
    at the outer surface of the particles from the second particle array.
    This uses a pysph nearest neighbour particles search which will output
    the particles within some range for every given particle.

    Parameters
    ----------
    fluid_parray : a pysph particle array object
    solid_parray : a pysph particle array object
    dx_solid : a number which is the dx of the second particle array
    dim : dimensionality of the problem

    The particle arrays should atleast contain x, y and h values for a 2d case
    and atleast x, y, z and h values for a 3d case

    Returns
    -------
    particle_array : pysph wcsph_particle_array with x, y, z and h values
    """

    x = fluid_parray.x
    x1 = solid_parray.x
    y = fluid_parray.y
    y1 = solid_parray.y
    z = fluid_parray.z
    z1 = solid_parray.z
    h = fluid_parray.h
    if dim == 2:
        z = np.zeros_like(x)
        z1 = np.zeros_like(x1)
    modified_points = []
    h_new = []
    ll_nnps = LinkedListNNPS(dim, [fluid_parray, solid_parray])
    for i in range(len(x)):
        nbrs = UIntArray()
        ll_nnps.get_nearest_particles(1, 0, i, nbrs)
        point_i = np.array([x[i], y[i], z[i]])
        near_points = nbrs.get_npy_array()
        distances = []
        for ind in near_points:
            dest = [x1[ind], y1[ind], z1[ind]]
            distances.append(distance(point_i, dest))
        if len(distances) == 0:
            modified_points.append(point_i)
            h_new.append(h[i])
        elif min(distances) >= (dx_solid * (1.0 - 1.0e-07)):
            modified_points.append(point_i)
            h_new.append(h[i])
    modified_points = np.array(modified_points)
    x_new = modified_points[:, 0]
    y_new = modified_points[:, 1]
    z_new = modified_points[:, 2]
    p_array = get_particle_array_wcsph(x=x_new, y=y_new, z=z_new, h=h_new)
    return p_array
Example #2
0
def time_pysph_nnps(pa, nbrs, num_particles):
    start_time = time.time()
    r = 1/1.101
    nn = LinkedListNNPS(dim=3, particles=[pa], radius_scale=r, cache=True)
    nn.set_context(0,0)
    for i in range(num_particles):
        nn.get_nearest_particles(0,0,i,nbrs)
    return time.time() - start_time
Example #3
0
def find_overlap_particles(fluid_parray, solid_parray, dx_solid, dim=3):
    """This function will take 2 particle arrays as input and will find all the
    particles of the first particle array which are in the vicinity of the
    particles from second particle array. The function will find all the
    particles within the dx_solid vicinity so some particles may be identified
    at the outer surface of the particles from the second particle array.

    The particle arrays should atleast contain x, y and h values for a 2d case
    and atleast x, y, z and h values for a 3d case.

    Parameters
    ----------
    fluid_parray : a pysph particle array object
    solid_parray : a pysph particle array object
    dx_solid : a number which is the dx of the second particle array
    dim : dimensionality of the problem

    Returns
    -------
    list of particle indices to remove from the first array.

    """

    x = fluid_parray.x
    x1 = solid_parray.x
    y = fluid_parray.y
    y1 = solid_parray.y
    z = fluid_parray.z
    z1 = solid_parray.z
    if dim == 2:
        z = np.zeros_like(x)
        z1 = np.zeros_like(x1)
    to_remove = []
    ll_nnps = LinkedListNNPS(dim, [fluid_parray, solid_parray])
    for i in range(len(x)):
        nbrs = UIntArray()
        ll_nnps.get_nearest_particles(1, 0, i, nbrs)
        point_i = np.array([x[i], y[i], z[i]])
        near_points = nbrs.get_npy_array()
        distances = []
        for ind in near_points:
            dest = [x1[ind], y1[ind], z1[ind]]
            distances.append(distance(point_i, dest))
        if len(distances) == 0:
            continue
        elif min(distances) < (dx_solid * (1.0 - 1.0e-07)):
            to_remove.append(i)
    return to_remove
Example #4
0
 def test_linked_list_nnps_large_num_cells(self):
     '''
     Tests LinkedListNNPS for large number of cells.
     Fails with a malloc error
     '''
     print ""
     for key in self.dataset_large_domain:
         x, y, z, h = self.dataset_large_domain[key]
         pa = get_particle_array(x=x, y=y, z=z, h=h)
         qid = randint(0,pa.get_number_of_particles()-1)
         nn_bf = brute_force_neighbours(pa, pa.x[qid], pa.y[qid],
                 pa.z[qid], pa.h[qid])
         r = 1/1.101
         sp = LinkedListNNPS(dim=3, particles=[pa], radius_scale=r, cache=True)
         nn_sp = UIntArray()
         sp.set_context(0,0)
         sp.get_nearest_particles(0,0,qid,nn_sp)
         print " - " + key
         assert equal(nn_bf, nn_sp)
Example #5
0
    def test_setting_use_cache_does_cache(self):
        # Given
        pa = self._make_random_parray('pa1', 3)
        pa.h[:] = 1.0
        nnps = LinkedListNNPS(dim=3, particles=[pa], cache=False)
        n = pa.get_number_of_particles()

        # When
        nnps.set_use_cache(True)
        nbrs = UIntArray()
        nnps.set_context(0, 0)
        for i in range(n):
            nnps.get_nearest_particles(0, 0, i, nbrs)

        # Then
        self.assertEqual(nbrs.length, n)
        # Find the length of all cached neighbors,
        # in this case, each particle has n neighbors,
        # so we should have n*n neighbors in all.
        total_length = sum(x.length for x in nnps.cache[0]._neighbor_arrays)
        self.assertEqual(total_length, n * n)
nps = LinkedListNNPS(dim=2, particles=[pa,], radius_scale=k.radius_scale, domain=domain)

# container for neighbors
nbrs = UIntArray()

# arrays including ghosts
x, y, h, m  = pa.get('x', 'y', 'h', 'm', only_real_particles=False)

# iterate over destination particles
t1 = time()
max_ngb = -1
for i in range( pa.num_real_particles ):
    xi = x[i]; yi = y[i]; hi = h[i]
    
    # get list of neighbors
    nps.get_nearest_particles(0, 0, i, nbrs)
    neighbors = nbrs.get_npy_array()

    max_ngb = max( neighbors.size, max_ngb )

    # iterate over the neighbor set
    rho_sum = 0.0; wij_sum = 0.0
    for j in neighbors:
        xij = xi - x[j]
        yij = yi - y[j]

        rij = numpy.sqrt( xij**2 + yij**2 )
        hij = 0.5 * (h[i] + h[j])

        _wij = k.kernel( [xij, yij, 0.0], rij, hij)
Example #7
0
# container for neighbors
nbrs = UIntArray()

# arrays including ghosts
x, y, h, m = pa.get('x', 'y', 'h', 'm', only_real_particles=False)

# iterate over destination particles
t1 = time()
max_ngb = -1
for i in range(pa.num_real_particles):
    xi = x[i]
    yi = y[i]
    hi = h[i]

    # get list of neighbors
    nps.get_nearest_particles(0, 0, i, nbrs)
    neighbors = nbrs.get_npy_array()

    max_ngb = max(neighbors.size, max_ngb)

    # iterate over the neighbor set
    rho_sum = 0.0
    wij_sum = 0.0
    for j in neighbors:
        xij = xi - x[j]
        yij = yi - y[j]

        rij = numpy.sqrt(xij**2 + yij**2)
        hij = 0.5 * (h[i] + h[j])

        _wij = k.kernel([xij, yij, 0.0], rij, hij)