Пример #1
0
def test_dry_spectrum_y(plot=False):
    settings = Settings()
    simulation = Simulation(settings)
    dry_volume = simulation.core.particles['dry volume'].to_ndarray()
    rd = phys.radius(volume=dry_volume) / si.nanometre
    nd = simulation.core.particles['n'].to_ndarray()

    dr = (rd[1:] - rd[0:-1])
    env = simulation.core.environment
    dn_dr = (nd[0:-1] / env.mass_of_dry_air * env["rhod"] / dr)
    dn_dr /= (1 / si.centimetre**3)

    if plot:
        plt.figure(figsize=(5, 5))
        plt.xscale('log')
        plt.yscale('log')
        plt.xlim(1e1, 1e3)
        plt.ylim(1e-9, 1e3)
        plt.yticks(10.**np.arange(-8, 3, step=2))
        plt.plot(rd[0:-1], dn_dr)
        plt.show()

    # from fig. 1b
    assert 1e-3 < dn_dr[0] < 1e-2
    assert 1e1 < max(dn_dr) < 1e2
    assert 0 < dn_dr[-1] < 1e-9
Пример #2
0
def test_RH():
    # Arrange
    settings = Settings()

    # Act
    simulation = Simulation(settings)

    # Assert
    assert round(simulation.core.environment["RH"][0], 3) == 0.856
Пример #3
0
def test_dry_spectrum_x():
    settings = Settings()
    simulation = Simulation(settings)
    dry_volume = simulation.core.particles['dry volume'].to_ndarray()
    rd = phys.radius(volume=dry_volume) / si.nanometre

    rd = rd[::-1]
    assert round(rd[1 - 1], 0) == 503
    assert round(rd[10 - 1], 0) == 355
    assert round(rd[50 - 1], 1) == 75.3
    assert round(rd[100 - 1], 1) == 10.8
Пример #4
0
def test_wet_vs_dry_spectrum(plot=False):
    # Arrange
    settings = Settings()

    # Act
    simulation = Simulation(settings)
    wet_volume = simulation.core.particles['volume'].to_ndarray()
    r_wet = phys.radius(volume=wet_volume) / si.nanometre
    n = simulation.core.particles['n'].to_ndarray()

    dry_volume = simulation.core.particles['dry volume'].to_ndarray()
    r_dry = phys.radius(volume=dry_volume) / si.nanometre

    # Plot
    if plot:
        plt.plot(r_wet, n)
        plt.plot(r_dry, n)
        plt.xscale('log')
        plt.yscale('log')
        plt.show()

    # Assert
    assert (r_dry < r_wet).all()
Пример #5
0
def test_displacement(plot=False):
    # Arrange
    settings = Settings(n_sd=1)
    simulation = Simulation(settings)

    # Act
    output = simulation.run()

    # Plot
    if plot:
        plt.plot(output["t"], output["S"])
        plt.grid()
        plt.show()

    # Assert
    assert np.argmin(output["z"]) == 0
    assert output["z"][0] == settings.z0
    np.testing.assert_approx_equal(output["z"][-1], 1000)
    np.testing.assert_approx_equal(np.amax(output["z"]), 1200)
    assert signal.argrelextrema(np.array(output["z"]),
                                np.greater)[0].shape[0] == 10
    assert signal.argrelextrema(np.array(output["z"]),
                                np.less)[0].shape[0] == 10
Пример #6
0
def test_just_do_it(scheme, coord, adaptive, enable_particle_temperatures):    # Arrange
    if scheme == 'BDF' and not adaptive:
        return
    if scheme == 'BDF' and coord == 'volume':
        return

    settings = Settings(dt_output=10 * si.second)
    settings.coord = coord
    settings.adaptive = adaptive
    settings.enable_particle_temperatures = enable_particle_temperatures
    if scheme == 'BDF':
        settings.dt_max = settings.dt_output
    elif not adaptive:
        settings.dt_max = 1 * si.second

    simulation = Simulation(settings)
    if scheme == 'BDF':
        bdf.patch_core(simulation.core, settings.coord)

    # Act
    output = simulation.run()
    r = np.array(output['r']).T * si.metres
    n = settings.n / (settings.mass_of_dry_air * si.kilogram)

    # Assert
    condition = (r > 1 * si.micrometre)
    NTOT = n_tot(n, condition)
    N1 = NTOT[: int(1/3 * len(NTOT))]
    N2 = NTOT[int(1/3 * len(NTOT)): int(2/3 * len(NTOT))]
    N3 = NTOT[int(2/3 * len(NTOT)):]

    n_unit = 1/si.microgram
    assert min(N1) == 0.0 * n_unit
    assert .63 * n_unit < max(N1) < .68 * n_unit
    assert .14 * n_unit < min(N2) < .15 * n_unit
    assert .3 * n_unit < max(N2) < .37 * n_unit
    assert .08 * n_unit < min(N3) < .083 * n_unit
    assert .27 * n_unit < max(N3) < .4 * n_unit
Пример #7
0
"""
Created at 25.11.2019
"""

from PySDM_examples.Yang_et_al_2018_Fig_2.settings import Settings
from PySDM_examples.Yang_et_al_2018_Fig_2.simulation import Simulation

if __name__ == '__main__':
    Simulation(settings=Settings()).run()