예제 #1
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 = DummyCore(backend, n_sd=1)
        particles.environment = DummyEnvironment(grid=grid)
        cell_id, cell_origin, position_in_cell = particles.mesh.cellular_attributes(
            initial_position)
        cell_origin[0, droplet_id] = .1
        cell_origin[1, droplet_id] = .2
        cell_id[droplet_id] = -1
        attribute = {
            'n': n,
            'cell id': cell_id,
            'cell origin': cell_origin,
            'position in cell': position_in_cell
        }
        particles.build(attribute)
        sut = particles.state

        # Act
        sut.recalculate_cell_id()

        # Assert
        assert sut['cell id'][droplet_id] == 0
예제 #2
0
    def get_displacement(self):
        core = DummyCore(Default, n_sd=len(self.n))
        core.environment = DummyEnvironment(
            dt=self.dt,
            grid=self.grid,
            courant_field_data=self.courant_field_data)
        positions = np.array(self.positions)
        cell_id, cell_origin, position_in_cell = core.mesh.cellular_attributes(
            positions)
        attributes = {
            'n': self.n,
            'cell id': cell_id,
            'cell origin': cell_origin,
            'position in cell': position_in_cell
        }
        core.build(attributes)
        sut = Displacement(scheme=self.scheme,
                           sedimentation=self.sedimentation)
        sut.register(core)

        return sut, core
예제 #3
0
def test_final_state(croupier, backend):
    from PySDM.backends import ThrustRTC
    if backend is ThrustRTC:
        return  # TODO #330

    # Arrange
    n_part = 100000
    v_mean = 2e-6
    d = 1.2
    n_sd = 32
    x = 4
    y = 4

    attributes = {}
    spectrum = Lognormal(n_part, v_mean, d)
    attributes['volume'], attributes['n'] = Linear(spectrum).sample(n_sd)
    core = DummyCore(backend, n_sd)
    core.environment = DummyEnvironment(grid=(x, y))
    core.croupier = croupier

    attributes['cell id'] = np.array((n_sd, ), dtype=int)
    cell_origin_np = np.concatenate(
        [np.random.randint(0, x, n_sd),
         np.random.randint(0, y, n_sd)]).reshape((2, -1))
    attributes['cell origin'] = cell_origin_np
    position_in_cell_np = np.concatenate(
        [np.random.rand(n_sd), np.random.rand(n_sd)]).reshape((2, -1))
    attributes['position in cell'] = position_in_cell_np
    core.build(attributes)

    # Act
    u01 = backend.Storage.from_ndarray(np.random.random(n_sd))
    core.particles.permutation(u01, local=core.croupier == 'local')
    _ = core.particles.cell_start

    # Assert
    assert (np.diff(core.particles['cell id'][core.particles._Particles__idx])
            >= 0).all()
예제 #4
0
    def get_displacement(self, backend, scheme):
        formulae = Formulae(particle_advection=scheme)
        core = DummyCore(backend, n_sd=len(self.n), formulae=formulae)
        core.environment = DummyEnvironment(
            dt=self.dt,
            grid=self.grid,
            courant_field_data=self.courant_field_data)
        positions = np.array(self.positions)
        cell_id, cell_origin, position_in_cell = core.mesh.cellular_attributes(
            positions)
        attributes = {
            'n': self.n,
            'volume': self.volume,
            'cell id': cell_id,
            'cell origin': cell_origin,
            'position in cell': position_in_cell
        }
        core.build(attributes)
        sut = Displacement(courant_field=self.courant_field_data,
                           enable_sedimentation=self.sedimentation)
        sut.register(core)

        return sut, core
예제 #5
0
def test_final_state(croupier):
    # Arrange
    n_part = 10000
    v_mean = 2e-6
    d = 1.2
    v_min = 0.01e-6
    v_max = 10e-6
    n_sd = 64
    x = 4
    y = 4

    attributes = {}
    spectrum = Lognormal(n_part, v_mean, d)
    attributes['volume'], attributes['n'] = linear(n_sd, spectrum,
                                                   (v_min, v_max))
    core = DummyCore(backend, n_sd)
    core.environment = DummyEnvironment(grid=(x, y))
    core.croupier = croupier

    attributes['cell id'] = backend.array((n_sd, ), dtype=int)
    cell_origin_np = np.concatenate(
        [np.random.randint(0, x, n_sd),
         np.random.randint(0, y, n_sd)]).reshape((2, -1))
    attributes['cell origin'] = backend.from_ndarray(cell_origin_np)
    position_in_cell_np = np.concatenate(
        [np.random.rand(n_sd), np.random.rand(n_sd)]).reshape((2, -1))
    attributes['position in cell'] = backend.from_ndarray(position_in_cell_np)
    core.build(attributes)

    # Act
    u01 = backend.Storage.from_ndarray(np.random.random(n_sd))
    core.state.permutation(u01)
    _ = core.state.cell_start

    # Assert
    assert (np.diff(core.state['cell id'][core.state._State__idx]) >= 0).all()
예제 #6
0
    def test_update(backend):
        # Arrange
        core = DummyCore(backend)
        halo = 3
        grid = (11, 13)
        env = DummyEnvironment(grid=grid, halo=halo)
        env.register(core)
        env.qv[:] = 7.3
        env.thd[:] = 59.5
        env.pred['qv'][:] = 3.7
        env.pred['thd'][:] = 5.59
        core.environment = env

        sut = EulerianAdvection(lambda: None)
        sut.register(core)

        # Act
        sut()

        # Assert
        np.testing.assert_array_equal(
            env.get_qv(),
            env.get_predicted('qv').to_ndarray().reshape(grid))
        np.testing.assert_array_equal(
            env.get_thd(),
            env.get_predicted('thd').to_ndarray().reshape(grid))