Exemplo n.º 1
0
 def get_dummy_particles_and_sdm(n_length):
     particles = DummyParticles(backend, n_sd=n_length, dt=0)
     dv = 1
     particles.set_mesh_0d(dv)
     particles.set_environment(Box, {})
     sdm = SDM(particles, StubKernel(particles.backend))
     return particles, sdm
Exemplo n.º 2
0
    def test_boundary_condition(self):
        # Arrange
        n = np.ones(1)
        grid = (1, 1)
        particles = DummyParticles(Default, n_sd=len(n))
        particles.set_mesh(grid)
        particles.set_environment(
            DummyEnvironment, ((np.array([[0, 0]]).T, np.array([[0, 0]])), ))
        droplet_id = 0
        positions = Default.from_ndarray(np.array([[0, 0]]))
        cell_id, cell_origin, position_in_cell = particles.mesh.cellular_attributes(
            positions)

        particles.state = StateFactory.state(n=n,
                                             intensive={},
                                             extensive={},
                                             cell_id=cell_id,
                                             cell_origin=cell_origin,
                                             position_in_cell=position_in_cell,
                                             particles=particles)
        sut = Advection(particles=particles)
        state = particles.state
        state.cell_origin[droplet_id, 0] = 1.1
        state.cell_origin[droplet_id, 1] = 1.2

        # Act
        sut.boundary_condition(state.cell_origin)

        # Assert
        assert state.cell_origin[droplet_id, 0] == 0
        assert state.cell_origin[droplet_id, 1] == 0
Exemplo n.º 3
0
    def test_calculate_displacement(self):
        # Arrange
        n = np.ones(1)
        grid = (1, 1)
        particles = DummyParticles(Default, n_sd=len(n))
        particles.set_mesh(grid)
        a = .1
        b = .2
        w = .25
        particles.set_environment(
            DummyEnvironment, ((np.array([[a, b]]).T, np.array([[0, 0]])), ))
        positions = Default.from_ndarray(np.array([[w, 0]]))
        cell_id, cell_origin, position_in_cell = particles.mesh.cellular_attributes(
            positions)

        particles.state = StateFactory.state(n=n,
                                             intensive={},
                                             extensive={},
                                             cell_id=cell_id,
                                             cell_origin=cell_origin,
                                             position_in_cell=position_in_cell,
                                             particles=particles)
        sut = Advection(particles=particles, scheme='FTFS')

        # Act
        sut.calculate_displacement(sut.displacement, sut.courant,
                                   particles.state.cell_origin,
                                   particles.state.position_in_cell)

        # Assert
        np.testing.assert_equal(sut.displacement[0, 0], (1 - w) * a + w * b)
Exemplo n.º 4
0
    def test_update_position(self):
        # Arrange
        n = np.ones(1)
        grid = (1, 1)
        particles = DummyParticles(Default, n_sd=len(n))
        particles.set_mesh(grid)
        particles.set_environment(
            DummyEnvironment, ((np.array([[0, 0]]).T, np.array([[0, 0]])), ))
        droplet_id = 0
        px = .1
        py = .2
        positions = Default.from_ndarray(np.array([[px, py]]))
        cell_id, cell_origin, position_in_cell = particles.mesh.cellular_attributes(
            positions)

        particles.state = StateFactory.state(n=n,
                                             intensive={},
                                             extensive={},
                                             cell_id=cell_id,
                                             cell_origin=cell_origin,
                                             position_in_cell=position_in_cell,
                                             particles=particles)
        sut = Advection(particles=particles)
        sut.displacement[droplet_id, 0] = .1
        sut.displacement[droplet_id, 1] = .2

        # Act
        sut.update_position(particles.state.position_in_cell, sut.displacement)

        # Assert
        for d in range(2):
            assert particles.state.position_in_cell[droplet_id, d] == (
                positions[droplet_id, d] + sut.displacement[droplet_id, d])
Exemplo n.º 5
0
    def test_boundary_condition(self):
        # Arrange
        n = np.ones(1, dtype=np.int64)
        grid = (1, 1)
        particles = DummyParticles(Default, n_sd=len(n), dt=1)
        particles.set_mesh(grid)
        particles.set_environment(
            DummyEnvironment, ((np.array([[0, 0]]).T, np.array([[0, 0]])), ))
        positions = Default.from_ndarray(np.array([[0, 0]]))
        cell_id, cell_origin, position_in_cell = particles.mesh.cellular_attributes(
            positions)

        particles.state = StateFactory.state(n=n,
                                             intensive={},
                                             extensive={},
                                             cell_id=cell_id,
                                             cell_origin=cell_origin,
                                             position_in_cell=position_in_cell,
                                             particles=particles)
        sut = Displacement(particles=particles, sedimentation=True)
        particles.set_terminal_velocity(ConstantTerminalVelocity)

        # Act
        sut()

        # Assert
        assert particles.state.SD_num == 0
Exemplo n.º 6
0
    def test_recalculate_cell_id(self):
        # Arrange
        n = np.ones(1, dtype=np.int64)
        droplet_id = 0
        initial_position = Default.from_ndarray(np.array([[0, 0]]))
        grid = (1, 1)
        particles = DummyParticles(backend, n_sd=1)
        particles.set_mesh(grid)
        particles.set_environment(DummyEnvironment, (None, ))
        sut = TestableStateFactory.state_2d(n=n,
                                            intensive={},
                                            extensive={},
                                            particles=particles,
                                            positions=initial_position)
        sut.cell_origin[droplet_id, 0] = .1
        sut.cell_origin[droplet_id, 1] = .2
        sut.cell_id[droplet_id] = -1

        # Act
        sut.recalculate_cell_id()

        # Assert
        assert sut.cell_id[droplet_id] == 0
Exemplo n.º 7
0
    def test_advection(self):
        n = np.ones(1)
        grid = (3, 3)
        particles = DummyParticles(Default, n_sd=len(n))
        particles.set_mesh(grid)
        particles.set_environment(DummyEnvironment, ((np.ones(
            (4, 3)), np.zeros((3, 4))), ))
        positions = Default.from_ndarray(np.array([[1.5, 1.5]]))
        cell_id, cell_origin, position_in_cell = particles.mesh.cellular_attributes(
            positions)

        particles.state = StateFactory.state(n=n,
                                             intensive={},
                                             extensive={},
                                             cell_id=cell_id,
                                             cell_origin=cell_origin,
                                             position_in_cell=position_in_cell,
                                             particles=particles)
        sut = Advection(particles=particles)

        sut()

        np.testing.assert_array_equal(particles.state.cell_origin[0, :],
                                      np.array([2, 1]))
Exemplo n.º 8
0
    def test_single_cell(self):

        # Arrange
        n = np.ones(1)
        grid = (1, 1)
        particles = DummyParticles(Default, n_sd=len(n))
        particles.set_mesh(grid)
        particles.set_environment(
            DummyEnvironment,
            ((np.array([[.1, .2]]).T, np.array([[.3, .4]])), ))
        positions = Default.from_ndarray(np.array([[0.5, 0.5]]))
        cell_id, cell_origin, position_in_cell = particles.mesh.cellular_attributes(
            positions)
        particles.state = StateFactory.state(n=n,
                                             intensive={},
                                             extensive={},
                                             cell_id=cell_id,
                                             cell_origin=cell_origin,
                                             position_in_cell=position_in_cell,
                                             particles=particles)
        sut = Advection(particles=particles)

        # Act
        sut()