Exemple #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.LinkedListNNPS(dim=1, particles=[pa], sort_gids=True)
        return pa, nps
Exemple #2
0
def test_use_3d_for_1d_data_with_llnps():
    y = numpy.array([1.0, 1.5])
    h = numpy.ones_like(y)
    pa = get_particle_array(name='fluid', y=y, h=h)
    nps = nnps.LinkedListNNPS(dim=3, particles=[pa], cache=False)
    nbrs = UIntArray()
    nps.get_nearest_particles(0, 0, 0, nbrs)
    print(nbrs.length)
    assert nbrs.length == len(y)
Exemple #3
0
    def post_process(self, info_fname):
        """
        Comparing wave height 0.05 m to the left of the tank
        """
        self.read_info(info_fname)

        if len(self.output_files) == 0:
            return

        from pysph.solver.utils import iter_output
        import matplotlib.pyplot as plt
        from cyarray.api import UIntArray
        from pysph.base import nnps

        files = self.output_files
        wave_height, t = [], []
        for sd, arrays1, arrays2 in iter_output(files, 'fluid', 'solid'):
            t.append(sd['t'])
            x_left = arrays2.x.min()
            probe_x = x_left + 0.05 + self.dx * (n_layers - 1)
            probe_y = np.linspace(0, arrays1.y.max(), 50)
            probe = get_particle_array(x=probe_x * np.ones_like(probe_y),
                                       y=probe_y)
            pa_list = [arrays1, probe]
            nps = nnps.LinkedListNNPS(dim=2, particles=pa_list, radius_scale=1)
            src_index, dst_index = 0, 1
            nps.set_context(src_index=0, dst_index=1)
            nbrs = UIntArray()
            wh = 0.0
            for i in range(len(probe_y)):
                nps.get_nearest_particles(src_index, dst_index, i, nbrs)
                neighbours = nbrs.get_npy_array()
                for j in range(len(neighbours)):
                    if arrays1.y[neighbours[j]] > wh:
                        wh = arrays1.y[neighbours[j]]

            wave_height.append(wh)

        wave_height = np.array(wave_height)
        wave_height = wave_height - h

        import pysph.examples.st_exp_data as st

        exp_t, exp_H = st.get_bouscasse_data()
        T = 2 * pi / omega
        t = np.array(t) / T
        plt.plot(t, wave_height, label="Computed")
        plt.scatter(exp_t, exp_H, label="Experiment: Bouscasse et al, 2013")
        plt.xlabel("t/T")
        plt.ylabel("Wave Height (m)")
        plt.xlim(8.5, 11)
        plt.legend()
        plt.savefig(os.path.join(self.output_dir, 'H_vs_t.png'))
        plt.show()
Exemple #4
0
def test_large_number_of_neighbors_linked_list():
    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.LinkedListNNPS(dim=3, particles=[pa], cache=False)
    nbrs = UIntArray()
    nps.get_nearest_particles(0, 0, 0, nbrs)
    # print(nbrs.length)
    assert nbrs.length == len(x)
Exemple #5
0
def test_neighbor_cache_update_doesnt_leak():
    # Given
    x, y, z = numpy.random.random((3, 1000))
    pa = get_particle_array(name='fluid', x=x, y=y, z=z, h=0.05)

    nps = nnps.LinkedListNNPS(dim=3, particles=[pa], cache=True)
    nps.set_context(0, 0)
    nps.cache[0].find_all_neighbors()
    old_length = sum(x.length for x in nps.cache[0]._neighbor_arrays)

    # When
    nps.update()
    nps.set_context(0, 0)
    nps.cache[0].find_all_neighbors()

    # Then
    new_length = sum(x.length for x in nps.cache[0]._neighbor_arrays)
    assert new_length == old_length
Exemple #6
0
 def setUp(self):
     NNPSTestCase.setUp(self)
     self.nps = nnps.LinkedListNNPS(
         dim=3, particles=self.particles, radius_scale=2.0
     )
Exemple #7
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]
        }
Exemple #8
0
            update_nstlist = False
        
        # update_dyn has the priority over update_nstlist
        update = False
        if update_dyn:
            update = True
        else:
            update = update_nstlist

        if update:
            
            print "Neighbor search",nl_updates
            
            pa = get_particle_array(name='prot', x=rx, y=ry, z=rz, h=1.0) #h=1.0 must not be changed as it affects radius_scale in nnps.LinkedListNNPS
            
            nps = nnps.LinkedListNNPS(dim=3, particles=[pa], radius_scale=rcut2)  
            #nps = nnps.SpatialHashNNPS(dim=3, particles=[pa], radius_scale=rcut2)  
            
            src_index = 0
            dst_index = 0
            neighbors = []
            tot = 0

            for i in range(nca):
                nbrs = UIntArray()
                nps.get_nearest_particles(src_index, dst_index, i, nbrs)
                tmp = nbrs.get_npy_array().tolist()
                
                # patch
                if tmp.count(i) > 1:
                    print "Problems: nbrs has multiple occurrences of residue %d, which might indicate something wrong in pysph (for certain radius_scale values)" %(i)