Пример #1
0
    def _make_particles(self, nx=20):
        x = numpy.linspace(0, 1, nx)
        h = numpy.ones_like(x) / (nx - 1)

        pa = get_particle_array(name='fluid', x=x, h=h)
        nps = nnps.SpatialHashNNPS(dim=1, particles=[pa], sort_gids=True)
        return pa, nps
Пример #2
0
def test_large_number_of_neighbors_spatial_hash():
    x = numpy.random.random(1 << 14) * 0.1
    y = x.copy()
    z = x.copy()
    h = numpy.ones_like(x)
    pa = get_particle_array(name='fluid', x=x, y=y, z=z, h=h)

    nps = nnps.SpatialHashNNPS(dim=3, particles=[pa], cache=False)
    nbrs = UIntArray()
    nps.get_nearest_particles(0, 0, 0, nbrs)
    # print(nbrs.length)
    assert nbrs.length == len(x)
Пример #3
0
 def test_spatial_hash_works_for_large_domain(self):
     # Given
     pa = self._make_particles(20)
     # We turn on cache so it computes all the neighbors quickly for us.
     nps = nnps.SpatialHashNNPS(dim=3, particles=[pa], cache=True)
     nbrs = UIntArray()
     direct = UIntArray()
     nps.set_context(0, 0)
     for i in range(pa.get_number_of_particles()):
         nps.get_nearest_particles(0, 0, i, nbrs)
         nps.brute_force_neighbors(0, 0, i, direct)
         x = nbrs.get_npy_array()
         y = direct.get_npy_array()
         x.sort(); y.sort()
         assert numpy.all(x == y)
Пример #4
0
 def setUp(self):
     NNPSTestCase.setUp(self)
     self.nps = nnps.SpatialHashNNPS(
         dim=3, particles=self.particles, radius_scale=2.0
     )
Пример #5
0
    def setUp(self):
        """Default set-up used by all the tests

        Particles with the following coordinates (x, y, z) are placed in a box

        0 : -1.5 , 0.25 , 0.5
        1 : 0.33 , -0.25, 0.25
        2 : 1.25 , -1.25, 1.25
        3 : 0.05 , 1.25 , -0.5
        4 : -0.5 , 0.5  , -1.25
        5 : -0.75, 0.75 , -1.25
        6 : -1.25, 0.5  , 0.5
        7 : 0.5  , 1.5  , -0.5
        8 : 0.5  , -0.5 , 0.5
        9 : 0.5  , 1.75 , -0.75

        The cell size is set to 1. Valid cell indices and the
        particles they contain are given below:

        (-2, 0, 0) : particle 0, 6
        (0, -1, 0) : particle 1, 8
        (1, -2, 1) : particle 2
        (0, 1, -1) : particle 3, 7, 9
        (-1, 0, -2): particle 4, 5

        """
        x = numpy.array([
            -1.5, 0.33, 1.25, 0.05, -0.5, -0.75, -1.25, 0.5, 0.5, 0.5])

        y = numpy.array([
            0.25, -0.25, -1.25, 1.25, 0.5, 0.75, 0.5, 1.5, -0.5, 1.75])

        z = numpy.array([
            0.5, 0.25, 1.25, -0.5, -1.25, -1.25, 0.5, -0.5, 0.5, -0.75])

        # using a degenrate (h=0) array will set cell size to 1 for NNPS
        h = numpy.zeros_like(x)

        pa = get_particle_array(x=x, y=y, z=z, h=h)

        self.dict_box_sort_nnps = nnps.DictBoxSortNNPS(
            dim=3, particles=[pa], radius_scale=1.0
        )

        self.box_sort_nnps = nnps.BoxSortNNPS(
            dim=3, particles=[pa], radius_scale=1.0
        )

        self.ll_nnps = nnps.LinkedListNNPS(
            dim=3, particles=[pa], radius_scale=1.0
        )

        self.sp_hash_nnps = nnps.SpatialHashNNPS(
            dim=3, particles=[pa], radius_scale=1.0
        )

        self.ext_sp_hash_nnps = nnps.ExtendedSpatialHashNNPS(
            dim=3, particles=[pa], radius_scale=1.0
        )

        self.strat_radius_nnps = nnps.StratifiedHashNNPS(
            dim=3, particles=[pa], radius_scale=1.0
        )

        # these are the expected cells
        self.expected_cells = {
            IntPoint(-2, 0, 0): [0, 6],
            IntPoint(0, -1, 0): [1, 8],
            IntPoint(1, -2, 1): [2],
            IntPoint(0, 1, -1): [3, 7, 9],
            IntPoint(-1, 0, -2): [4, 5]
        }