示例#1
0
    def test_permutation_local(backend):
        if backend == GPU:  # TODO #358
            return
        n_sd = 8
        u01 = [.1, .4, .2, .5, .9, .1, .6, .3]
        cell_start = [0, 0, 2, 5, 7, n_sd]

        # Arrange
        particulator = DummyParticulator(backend, n_sd=n_sd)
        sut = ParticlesFactory.empty_particles(particulator, n_sd)
        idx_length = len(sut._Particles__idx)
        sut._Particles__tmp_idx = TestParticles.make_indexed_storage(
            backend, [0] * idx_length)
        sut._Particles__cell_start = TestParticles.make_indexed_storage(
            backend, cell_start)
        sut._Particles__sorted = True
        sut._Particles__n_sd = particulator.n_sd
        u01 = TestParticles.make_indexed_storage(backend, u01)

        # Act
        sut.permutation(u01, local=True)

        # Assert
        expected = np.array([1, 0, 2, 3, 4, 5, 6, 7])
        np.testing.assert_array_equal(sut._Particles__idx, expected)
        assert sut._Particles__sorted
示例#2
0
    def test_permutation_global_repeatable(backend):
        from PySDM.backends import ThrustRTC
        if backend is ThrustRTC:
            return  # TODO #328

        n_sd = 800
        u01 = np.random.random(n_sd)

        # Arrange
        particulator = DummyParticulator(backend, n_sd=n_sd)
        sut = ParticlesFactory.empty_particles(particulator, n_sd)
        idx_length = len(sut._Particles__idx)
        sut._Particles__tmp_idx = TestParticles.make_indexed_storage(
            backend, [0] * idx_length)
        sut._Particles__sorted = True
        u01 = TestParticles.make_indexed_storage(backend, u01)

        # Act
        sut.permutation(u01, local=False)
        expected = sut._Particles__idx.to_ndarray()
        sut._Particles__sorted = True
        sut._Particles__idx = TestParticles.make_indexed_storage(
            backend, range(n_sd))
        sut.permutation(u01, local=False)

        # Assert
        np.testing.assert_array_equal(sut._Particles__idx, expected)
        assert not sut._Particles__sorted
示例#3
0
    def build(self,
              attributes: dict,
              products: list = (),
              int_caster=discretise_n):
        assert self.particulator.environment is not None

        for dynamic in self.particulator.dynamics.values():
            dynamic.register(self)

        for product in products:
            self.register_product(product)

        for attribute in attributes:
            self.request_attribute(attribute)
        if 'Condensation' in self.particulator.dynamics:
            self.particulator.condensation_solver = \
                self.particulator.backend.make_condensation_solver(self.particulator.dt, self.particulator.mesh.n_cell, **self.condensation_params)
        attributes['n'] = int_caster(attributes['n'])
        if self.particulator.mesh.dimension == 0:
            attributes['cell id'] = np.zeros_like(attributes['n'],
                                                  dtype=np.int64)
        self.particulator.attributes = ParticlesFactory.attributes(
            self.particulator, self.req_attr, attributes)

        for key in self.particulator.dynamics:
            self.particulator.timers[key] = WallTimer()

        return self.particulator
示例#4
0
    def test_permutation_global(backend):
        from PySDM.backends import ThrustRTC
        if backend is ThrustRTC:
            return  # TODO

        n_sd = 8
        u01 = [.1, .4, .2, .5, .9, .1, .6, .3]

        # Arrange
        core = DummyCore(backend, n_sd=n_sd)
        sut = ParticlesFactory.empty_particles(core, n_sd)
        idx_length = len(sut._Particles__idx)
        sut._Particles__tmp_idx = TestParticles.make_storage(
            backend, [0] * idx_length)
        sut._Particles__sorted = True
        sut._Particles__n_sd = core.n_sd
        u01 = TestParticles.make_storage(backend, u01)

        # Act
        sut.permutation(u01, local=False)

        # Assert
        expected = np.array([1, 3, 5, 7, 6, 0, 4, 2])
        np.testing.assert_array_equal(sut._Particles__idx, expected)
        assert not sut._Particles__sorted
示例#5
0
    def build(self,
              attributes: dict,
              products: list = (),
              int_caster=discretise_n):
        self.core.backend.sanity_check()

        for dynamic in self.core.dynamics.values():
            dynamic.register(self)

        for product in products:
            self.register_product(product)

        for attribute in attributes:
            self.request_attribute(attribute)
        if 'Condensation' in self.core.dynamics:
            self.core.condensation_solver = \
                self.core.backend.make_condensation_solver(self.core.dt, **self.condensation_params)
        attributes['n'] = int_caster(attributes['n'])
        if self.core.mesh.dimension == 0:
            attributes['cell id'] = np.zeros_like(attributes['n'],
                                                  dtype=np.int64)
        self.core.particles = ParticlesFactory.attributes(
            self.core, self.req_attr, attributes)

        for key in self.core.dynamics.keys():
            self.core.timers[key] = WallTimer()

        return self.core
示例#6
0
    def test_permutation_global_as_implemented_in_Numba():
        n_sd = 8
        u01 = [.1, .4, .2, .5, .9, .1, .6, .3]

        # Arrange
        core = DummyCore(CPU, n_sd=n_sd)
        sut = ParticlesFactory.empty_particles(core, n_sd)
        idx_length = len(sut._Particles__idx)
        sut._Particles__tmp_idx = TestParticles.make_indexed_storage(CPU, [0] * idx_length)
        sut._Particles__sorted = True
        sut._Particles__n_sd = core.n_sd
        u01 = TestParticles.make_indexed_storage(CPU, u01)

        # Act
        sut.permutation(u01, local=False)

        # Assert
        expected = np.array([1, 3, 5, 7, 6, 0, 4, 2])
        np.testing.assert_array_equal(sut._Particles__idx, expected)
        assert not sut._Particles__sorted
示例#7
0
    def build(self, attributes: dict, products: list = ()):
        for dynamic in self.core.dynamics.values():
            dynamic.register(self)

        for product in products:
            self.register_product(product)

        for attribute in attributes:
            self.request_attribute(attribute)
        if 'Condensation' in self.core.dynamics:
            self.core.condensation_solver = \
                self.core.backend.make_condensation_solver(**self.condensation_params,
                                                           enable_drop_temperatures='temperatures' in self.req_attr)
        attributes['n'] = discretise_n(attributes['n'])
        if self.core.mesh.dimension == 0:
            attributes['cell id'] = np.zeros_like(attributes['n'],
                                                  dtype=np.int64)  # TODO
        self.core.particles = ParticlesFactory.attributes(
            self.core, self.req_attr, attributes)

        return self.core
示例#8
0
    def test_permutation_local(backend):
        n_sd = 8
        u01 = [.1, .4, .2, .5, .9, .1, .6, .3]
        cell_start = [0, 0, 2, 5, 7, n_sd]

        # Arrange
        core = DummyCore(backend, n_sd=n_sd)
        sut = ParticlesFactory.empty_particles(core, n_sd)
        idx_length = len(sut._Particles__idx)
        sut._Particles__tmp_idx = TestParticles.make_storage(
            backend, [0] * idx_length)
        sut._Particles__cell_start = TestParticles.make_storage(
            backend, cell_start)
        sut._Particles__sorted = True
        sut._Particles__n_sd = core.n_sd
        u01 = TestParticles.make_storage(backend, u01)

        # Act
        sut.permutation(u01, local=True)

        # Assert
        expected = np.array([1, 0, 2, 3, 4, 5, 6, 7])
        np.testing.assert_array_equal(sut._Particles__idx, expected)
        assert sut._Particles__sorted