Example #1
0
    def _get_end_points(self):
        """
        Return changed end points so that start_point to end_point is moving in
        positive direction for all coords.
        """
        length = self.end_point.x - self.start_point.x
        depth = self.end_point.y - self.start_point.y
        width = self.end_point.z - self.start_point.z

        start_point = Point()
        end_point = Point()

        if length < 0:
            start_point.x = self.end_point.x
            end_point.x = self.start_point.x
        else:
            start_point.x = self.start_point.x
            end_point.x = self.end_point.x

        if depth < 0:
            start_point.y = self.end_point.y
            end_point.y = self.start_point.y
        else:
            start_point.y = self.start_point.y
            end_point.y = self.end_point.y

        if width < 0:
            start_point.z = self.end_point.z
            end_point.z = self.start_point.z
        else:
            start_point.z = self.start_point.z
            end_point.z = self.end_point.z
            
        return start_point, end_point, abs(length), abs(depth), abs(width)
Example #2
0
def compute_particle_mass(parray, kernel, density=1000.0, h=0.1, dim=3):
    """
    Given a particle array, kernel, target density and interaction radius, find
    the mass of each particle.

    Note that this method works only when the particle radius is constant. This
    may also compute incorrect values when the particle cofiguration has voids
    within.
    """
    centroid = Point(0, 0, 0)
    dist = DoubleArray(0)
    indices = LongArray(0)
    
    x = parray.get('x')
    centroid.x = numpy.sum(x)/float(len(x))
    y = None
    z = None

    logger.debug('particles to compute_particle_mass %d'%(len(x)))
    
    if dim > 1:
        y = parray.get('y')
        centroid.y = numpy.sum(y)/float(len(y))
        if dim > 2:
            z = parray.get('z')
            centroid.z = numpy.sum(z)/float(len(z))
        else:
            z = numpy.zeros(len(x), dtype=numpy.float)
    else:
        y = numpy.zeros(len(x), dtype=numpy.float)
        z = y

    logger.debug('Centroid : %s'%(centroid))
    radius = kernel.radius()
    
    # find the nearest points in parray of the centroid.
    brute_force_nnps(pnt=centroid, search_radius=h*radius, 
                     xa=x, ya=y, za=z, 
                     neighbor_indices=indices,
                     neighbor_distances=dist)
    
    k = 0.0
    logger.info('Number of neighbors : %d'%(indices.length))
    pnt = Point()
    for i in range(indices.length):
        pnt.x = x[indices[i]]
        pnt.y = y[indices[i]]
        pnt.z = z[indices[i]]
        
        k += kernel.py_function(centroid, pnt, h)

    logger.info('Kernel sum : %f'%(k))
    logger.info('Requested density : %f'%(density))
    m = float(density/k)
    logger.info('Computed mass : %f'%(m))
    return m