示例#1
0
    def test_multi_collision(self, v_2, n_2, p):
        # Arrange
        particles, sut = TestSDMSingleCell.get_dummy_particles_and_sdm(
            len(n_2))
        sut.compute_gamma = lambda prob, rand: backend_fill(backend, prob, p)
        particles.state = TestableStateFactory.state_0d(
            n=n_2,
            extensive={'volume': v_2},
            intensive={},
            particles=particles)

        # Act
        sut()

        # Assert
        state = particles.state
        gamma = min(p, max(n_2[0] // n_2[1], n_2[1] // n_2[1]))
        assert np.amin(state['n']) >= 0
        assert np.sum(state['n'] * state['volume']) == np.sum(n_2 * v_2)
        assert np.sum(state['n']) == np.sum(n_2) - gamma * np.amin(n_2)
        assert np.amax(
            state['volume']
        ) == gamma * v_2[np.argmax(n_2)] + v_2[np.argmax(n_2) - 1]
        assert np.amax(state['n']) == max(
            np.amax(n_2) - gamma * np.amin(n_2), np.amin(n_2))
示例#2
0
    def test_single_collision(self, v_2, T_2, n_2):
        # Arrange
        particles, sut = TestSDMSingleCell.get_dummy_particles_and_sdm(
            len(n_2))
        sut.compute_gamma = lambda prob, rand: backend_fill(backend, prob, 1)
        particles.state = TestableStateFactory.state_0d(
            n=n_2,
            extensive={'volume': v_2},
            intensive={'temperature': T_2},
            particles=particles)

        # Act
        sut()

        # Assert
        state = particles.state
        assert np.sum(state['n'] * state['volume'] *
                      state['temperature']) == np.sum(n_2 * T_2 * v_2)
        new_T = np.sum(T_2 * v_2) / np.sum(v_2)
        assert np.isin(round(new_T, 10), np.round(state['temperature'], 10))

        assert np.sum(particles.state['n'] *
                      particles.state['volume']) == np.sum(n_2 * v_2)
        assert np.sum(particles.state['n']) == np.sum(n_2) - np.amin(n_2)
        if np.amin(n_2) > 0:
            assert np.amax(particles.state['volume']) == np.sum(v_2)
        assert np.amax(particles.state['n']) == max(
            np.amax(n_2) - np.amin(n_2), np.amin(n_2))
示例#3
0
    def test_multi_droplet(self, x, n, p):
        # Arrange
        particles, sut = TestSDMSingleCell.get_dummy_particles_and_sdm(len(n))
        sut.compute_gamma = lambda prob, rand: backend_fill(
            backend, prob, p, True)
        particles.state = TestableStateFactory.state_0d(
            n=n, extensive={'volume': x}, intensive={}, particles=particles)

        # Act
        sut()

        # Assert
        assert np.amin(particles.state['n']) >= 0
        assert np.sum(particles.state['n'] *
                      particles.state['volume']) == np.sum(n * x)
示例#4
0
    def test_single_collision_same_n(self, n_in, n_out):
        # Arrange
        particles, sut = TestSDMSingleCell.get_dummy_particles_and_sdm(2)
        sut.compute_gamma = lambda prob, rand: backend_fill(backend, prob, 1)
        particles.state = TestableStateFactory.state_0d(
            n=np.full(2, n_in),
            extensive={'volume': np.full(2, 1.)},
            intensive={},
            particles=particles)

        # Act
        sut()

        # Assert
        np.testing.assert_array_equal(
            sorted(particles.backend.to_ndarray(particles.state.n)),
            sorted(n_out))
示例#5
0
 def test_single_collision(self, x_2, n_2):
     # Arrange
     particles, sut = TestSDMSingleCell.get_dummy_particles_and_sdm(
         len(n_2))
     sut.compute_gamma = lambda prob, rand: backend_fill(backend, prob, 1)
     particles.state = TestableStateFactory.state_0d(
         n=n_2,
         extensive={'volume': x_2},
         intensive={},
         particles=particles)
     # Act
     sut()
     # Assert
     assert np.sum(particles.state['n'] *
                   particles.state['volume']) == np.sum(n_2 * x_2)
     assert np.sum(particles.state['n']) == np.sum(n_2) - np.amin(n_2)
     if np.amin(n_2) > 0:
         assert np.amax(particles.state['volume']) == np.sum(x_2)
     assert np.amax(particles.state['n']) == max(
         np.amax(n_2) - np.amin(n_2), np.amin(n_2))
示例#6
0
    def test_multi_step(self):
        # Arrange
        n_sd = 256
        n = np.random.randint(1, 64, size=n_sd)
        x = np.random.uniform(size=n_sd)

        particles, sut = TestSDMSingleCell.get_dummy_particles_and_sdm(n_sd)

        sut.compute_gamma = lambda prob, rand: backend_fill(
            backend, prob, backend.to_ndarray(rand) > 0.5, odd_zeros=True)
        particles.state = TestableStateFactory.state_0d(
            n=n, extensive={'volume': x}, intensive={}, particles=particles)

        # Act
        for _ in range(32):
            sut()

        # Assert
        assert np.amin(particles.state['n']) >= 0
        actual = np.sum(particles.state['n'] * particles.state['volume'])
        desired = np.sum(n * x)
        np.testing.assert_almost_equal(actual=actual, desired=desired)