コード例 #1
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_core(simulation.core)
                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
コード例 #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]
コード例 #3
0
def test_just_do_it(backend, scheme, adaptive):
    # Arrange
    if scheme == 'BDF' and (not adaptive or backend is GPU):
        return

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

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

    # 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 .6 * n_unit < max(N1) < .8 * n_unit
    assert .17 * n_unit < min(N2) < .18 * n_unit
    assert .35 * n_unit < max(N2) < .41 * n_unit
    assert .1 * n_unit < min(N3) < .11 * n_unit
    assert .27 * n_unit < max(N3) < .4 * n_unit

    # TODO #527
    if backend is not GPU:
        assert max(output['ripening_rate']) > 0
コード例 #4
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)