コード例 #1
0
ファイル: test_spectra.py プロジェクト: huangynj/PySDM
    def test_underflow(self):
        np.seterr(all='raise')  # TODO: use with construct

        norm_factor = 1e10
        scale = 1e-13
        sut = Exponential(norm_factor, scale)

        x = 5e-10
        value = sut.size_distribution(x)

        assert value != 0
コード例 #2
0
    def test_size_distribution_n_part(self, scale):
        # Arrange
        scale = 1
        n_part = 256
        sut = Exponential(n_part, scale)

        # Act
        m, dm = np.linspace(0, 5, 10000, retstep=True)
        sd = sut.size_distribution(m)

        # Assert
        assert_approx_equal(np.sum(sd) * dm, n_part, 2)
コード例 #3
0
ファイル: test_coalescence.py プロジェクト: huangynj/PySDM
def test_coalescence():
    # TODO: np.random.RandomState in backend?

    # Arrange
    v_min = 4.186e-15
    v_max = 4.186e-12
    n_sd = 2**13
    steps = [0, 30, 60]
    X0 = 4 / 3 * 3.14 * 30.531e-6**3
    n_part = 2**23  # [m-3]
    dv = 1e6  # [m3]
    dt = 1  # [s]
    norm_factor = n_part * dv

    kernel = Golovin(b=1.5e3)  # [s-1]
    spectrum = Exponential(norm_factor=norm_factor, scale=X0)
    particles = Particles(n_sd=n_sd, dt=dt, backend=backend)
    particles.set_mesh_0d(dv=dv)
    particles.set_environment(Box, {})
    v, n = constant_multiplicity(n_sd, spectrum, (v_min, v_max))
    particles.create_state_0d(n=n, extensive={'volume': v}, intensive={})
    particles.add_dynamic(SDM, {"kernel": kernel})

    states = {}

    # Act
    for step in steps:
        particles.run(step - particles.n_steps)
        states[particles.n_steps] = copy.deepcopy(particles.state)

    # Assert
    x_max = 0
    for state in states.values():
        assert x_max < state.max('volume')
        x_max = state.max('volume')
コード例 #4
0
ファイル: setup.py プロジェクト: cycle13/PySDM
class SetupA:
    x_min = phys.volume(radius=10 * si.micrometres)  # not given in the paper
    x_max = phys.volume(radius=100 * si.micrometres)  # not given in the paper

    n_sd = 2 ** 13
    n_part = 2 ** 23 / si.metre**3
    X0 = 4 / 3 * np.pi * 30.531e-6 ** 3
    dv = 1e6 * si.metres**3
    norm_factor = n_part * dv
    rho = 1000 * si.kilogram / si.metre**3
    dt = 1 * si.seconds
    seed = 44
    steps = [0, 1200, 2400, 3600]

    kernel = Golovin(b=1.5e3 / si.second)
    spectrum = Exponential(norm_factor=norm_factor, scale=X0)

    backend = Default

    # TODO: rename?
    # TODO: as backend method?
    def check(self, state, step):
        check_LWC = 1e-3  * si.kilogram / si.metre**3
        check_ksi = self.n_part * self.dv / self.n_sd

        # multiplicities
        if step == 0:
            np.testing.assert_approx_equal(np.amin(state['n']), np.amax(state['n']), 1)
            np.testing.assert_approx_equal(state['n'][0], check_ksi, 1)

        # liquid water content
        LWC = self.rho * np.dot(state['n'], state['volume']) / self.dv
        np.testing.assert_approx_equal(LWC, check_LWC, 3)