Beispiel #1
0
def test_event_rates(settings_idx):
    # Arrange
    settings = Settings(w_avg=setups[settings_idx].w_avg,
                        N_STP=setups[settings_idx].N_STP,
                        r_dry=setups[settings_idx].r_dry,
                        mass_of_dry_air=1 * si.kg)
    const = settings.formulae.constants
    settings.n_output = 50
    simulation = Simulation(settings)

    # Act
    output = simulation.run()

    # Assert
    rip = np.asarray(output['ripening_rate'])
    act = np.asarray(output['activating_rate'])
    dea = np.asarray(output['deactivating_rate'])
    act_max = np.full(
        (1, ), settings.n_in_dv / simulation.particulator.dt / const.rho_STP)
    convert_to(act_max, 1 / si.mg)
    assert (rip == 0).all()
    assert (act > 0).any()
    assert (dea > 0).any()
    assert 0 < max(act) < act_max[0]
    assert 0 < max(dea) < act_max[0]
Beispiel #2
0
def test_water_mass_conservation(settings_idx, mass_of_dry_air, scheme, coord):
    # Arrange
    assert scheme in ('BDF', 'CPU', 'GPU')

    settings = Settings(
        w_avg=setups[settings_idx].w_avg,
        N_STP=setups[settings_idx].N_STP,
        r_dry=setups[settings_idx].r_dry,
        mass_of_dry_air=mass_of_dry_air,
        coord=coord
    )
    settings.n_output = 50
    settings.coord = coord
    simulation = Simulation(settings, GPU if scheme == 'GPU' else CPU)
    qt0 = settings.q0 + ql(simulation)

    if scheme == 'BDF':
        bdf.patch_core(simulation.core)

    # Act
    simulation.core.products['S_max'].get()
    output = simulation.run()

    # Assert
    qt = simulation.core.environment["qv"].to_ndarray() + ql(simulation)
    significant = 6 if scheme == 'GPU' else 14  # TODO #540
    np.testing.assert_approx_equal(qt, qt0, significant)
    if scheme != 'BDF':
        assert simulation.core.products['S_max'].get() >= output['S'][-1]
Beispiel #3
0
def test_energy_conservation(settings_idx, mass_of_dry_air, coord):
    # Arrange
    settings = Settings(w_avg=setups[settings_idx].w_avg,
                        N_STP=setups[settings_idx].N_STP,
                        r_dry=setups[settings_idx].r_dry,
                        mass_of_dry_air=mass_of_dry_air,
                        coord=coord)
    simulation = Simulation(settings)
    env = simulation.particulator.environment
    thd0 = env['thd']

    # Act
    simulation.run()

    # Assert
    np.testing.assert_approx_equal(thd0.to_ndarray(), env['thd'].to_ndarray())
def test_displacement(w_idx):
    # Arrange
    settings = Settings(w_avg=w_avgs[w_idx],
                        N_STP=44,
                        r_dry=1,
                        mass_of_dry_air=1)
    settings.n_output = 50
    simulation = Simulation(settings)

    # Act
    output = simulation.run()

    # Assert
    np.testing.assert_almost_equal(min(output["z"]), 0, decimal=1)
    np.testing.assert_almost_equal(max(output["z"]),
                                   settings.z_half,
                                   decimal=1)
Beispiel #5
0
def data(n_output, rtols, schemes, setups_num):
    resultant_data = {}
    for scheme in schemes:
        resultant_data[scheme] = {}
        if scheme == "BDF":
            for rtol in rtols:
                resultant_data[scheme][rtol] = []
            for settings_idx in range(setups_num):
                settings = setups[settings_idx]
                settings.n_output = n_output
                simulation = Simulation(settings)
                bdf.patch_particulator(simulation.particulator)
                results = simulation.run()
                for rtol in rtols:
                    resultant_data[scheme][rtol].append(results)
        else:
            for rtol in rtols:
                resultant_data[scheme][rtol] = []
                for settings_idx in range(setups_num):
                    settings = setups[settings_idx]
                    settings.rtol_x = rtol
                    settings.rtol_thd = rtol
                    settings.n_output = n_output
                    simulation = Simulation(
                        settings, backend=CPU if scheme == "CPU" else GPU)
                    results = simulation.run()
                    resultant_data[scheme][rtol].append(results)
    return resultant_data
Beispiel #6
0
def test_water_mass_conservation(settings_idx, mass_of_dry_air, scheme, coord):
    # Arrange
    settings = Settings(w_avg=setups[settings_idx].w_avg,
                        N_STP=setups[settings_idx].N_STP,
                        r_dry=setups[settings_idx].r_dry,
                        mass_of_dry_air=mass_of_dry_air,
                        coord=coord)
    settings.n_output = 50
    settings.coord = coord
    simulation = Simulation(settings)
    qt0 = settings.q0 + ql(simulation)

    assert scheme in ('BDF', 'default')
    if scheme == 'BDF':
        bdf.patch_core(simulation.core)

    # Act
    simulation.run()

    # Assert
    qt = simulation.core.environment["qv"].to_ndarray() + ql(simulation)
    np.testing.assert_approx_equal(qt, qt0, 14)
 def simulation_test(var, expected, setup):
     simulation = Simulation(setup)
     np.testing.assert_approx_equal(simulation.particulator.environment[var].to_ndarray(), expected)
Beispiel #8
0
def main():
    for settings in setups:
        Simulation(settings).run()