Example #1
0
def test_few_steps(backend, plot=False):
    # Arrange
    settings = Settings(n_sd_per_gridbox=50, dt=30 * si.s, dz=50 * si.m)
    simulation = Simulation(settings)

    # Act
    output = simulation.run(nt=100)

    # Plot
    def profile(var):
        return np.mean(output[var][:, -20:], axis=1)

    if plot:
        from matplotlib import pyplot
        for var in ('RH_env', 'S_max', 'T_env', 'qv_env', 'p_env', 'ql',
                    'ripening_rate', 'activating_rate', 'deactivating_rate'):
            pyplot.plot(profile(var), output['z'], linestyle='--', marker='o')
            pyplot.ylabel('Z [m]')
            pyplot.xlabel(var + ' [' +
                          simulation.particulator.products[var].unit + ']')
            pyplot.grid()
            pyplot.show()

    # Assert
    assert min(profile('ql')) == 0
    assert .1 < max(profile('ql')) < 1
    # assert max(profile('ripening_rate')) > 0 # TODO #521
    assert max(profile('activating_rate')) == 0
Example #2
0
    def test_initial_condition(plot=False):
        # Arrange
        settings = Settings(n_sd_per_gridbox=100, rho_times_w_1=1 * si.m / si.s)
        simulation = Simulation(settings)

        # Act
        output = simulation.run(nt=0)

        # Plot
        if plot:
            from matplotlib import pyplot
            for var in ('RH_env', 'T_env', 'qv_env', 'p_env'):
                pyplot.plot(output[var][:, 0], output['z'], linestyle='--', marker='o')
                pyplot.ylabel('Z [m]')
                pyplot.xlabel(var + ' [' + simulation.particulator.products[var].unit + ']')
                pyplot.grid()
                pyplot.show()

        # Assert
        assert output['RH_env'].shape == (settings.nz, 1)

        assert 35 < np.amin(output['RH_env']) < 40
        assert 110 < np.amax(output['RH_env']) < 115

        assert 700 * si.hPa < np.amin(output['p_env']) < 710 * si.hPa
        assert (np.diff(output['p_env']) < 0).all()
        assert 950 * si.hPa < np.amax(output['p_env']) < 1000 * si.hPa

        assert 280 * si.K < np.amin(output['T_env']) < 285 * si.K
        assert output['T_env'][0] > np.amin(output['T_env'])
        assert 295 * si.K < np.amax(output['T_env']) < 300 * si.K
Example #3
0
 def test_instantiate():
     _ = Settings(n_sd_per_gridbox=1, w_1=1)
Example #4
0
 def test_rhod():
     settings = Settings(n_sd_per_gridbox=1, w_1=1)
     assert settings.rhod  # TODO #414
Example #5
0
 def test_qv():
     settings = Settings(n_sd_per_gridbox=1, w_1=1)
     assert settings.qv(0) == .015
     assert settings.qv(740) == .0138
     np.testing.assert_approx_equal(settings.qv(3260), .0024)
Example #6
0
 def test_th():
     settings = Settings(n_sd_per_gridbox=1, w_1=1)
     assert settings._th(0) == 297.9
     assert settings._th(100) == 297.9
     assert settings._th(740) == 297.9
     assert settings._th(3260) == 312.66
Example #7
0
 def test_instantiate():
     _ = Settings(n_sd_per_gridbox=1, rho_times_w_1=1)
Example #8
0
 def test_rhod():
     settings = Settings(n_sd_per_gridbox=1, rho_times_w_1=1)
     assert settings.rhod