Esempio n. 1
0
def data():
    result, _ = compute_figure_data(nr=default_nr,
                                    GC_max=default_GC_max,
                                    psi_coord=x_id(),
                                    grid_layouts=grid_layout_set,
                                    opt_set=opt_set)
    return result
Esempio n. 2
0
def compute_figure_data(*,
                        nr,
                        GC_max,
                        psi_coord=x_id(),
                        grid_layouts=(x_id(), x_p2(), x_log_of_pn(n=1)),
                        opt_set=({
                            'n_iters': 1
                        }, ),
                        mixing_ratios_g_kg=default_mixing_ratios_g_kg):
    setup = Setup(nr=nr, mixing_ratios_g_kg=mixing_ratios_g_kg)
    with parallel_backend('threading', n_jobs=-2):
        results = Parallel(verbose=10)(
            delayed(analysis)(setup, grid_layout, psi_coord, options, GC_max)
            for grid_layout in grid_layouts for options in deepcopy(opt_set))

    cases = {}
    for result in results:
        case = Case(result)
        if case.grid_layour_str not in cases:
            cases[case.grid_layour_str] = case
Esempio n. 3
0
def make_data(setup, grid, opts):
    options = Options(**opts)
    simulation = Simulation(setup=setup,
                            grid_layout=grid,
                            psi_coord=x_id(),
                            opts=options,
                            GC_max=default_GC_max)
    result = {"wall_time": []}
    last_step = 0
    for n_steps in simulation.out_steps:
        steps = n_steps - last_step
        wall_time_per_timestep = simulation.step(steps)
        last_step += steps
        result['wall_time'].append(wall_time_per_timestep)
    return result
Esempio n. 4
0
from MPyDATA_examples.Olesik_et_al_2020.physics.East_and_Marshall_1954 import SizeDistribution
from MPyDATA.arakawa_c.discretisation import discretised_analytical_solution
import pint
from matplotlib import pyplot
import numpy as np
from MPyDATA_examples.Olesik_et_al_2020.coordinates import x_id, x_log_of_pn, x_p2
import pytest


def diff(x):
    return np.diff(x.magnitude) * x.units


@pytest.mark.parametrize("grid", [x_id(), x_log_of_pn(r0=1), x_p2()])
@pytest.mark.parametrize("coord", [x_id(), x_log_of_pn(r0=1), x_p2()])
def test_size_distribution(grid, coord, plot=False):
    # Arrange
    si = pint.UnitRegistry()
    sd = SizeDistribution(si)
    n_unit = si.centimetres**-3 / si.micrometre
    r_unit = si.micrometre

    # Act
    x = grid.x(np.linspace(1, 18, 100)) * r_unit
    dx_dr = coord.dx_dr
    numpdfx = x[1:] - diff(x) / 2
    pdf_t = lambda r: sd.pdf(r * r_unit).to(n_unit).magnitude / dx_dr(
        r * r_unit).magnitude
    numpdfy = discretised_analytical_solution(rh=x.magnitude,
                                              pdf_t=pdf_t) * n_unit
Esempio n. 5
0
from MPyDATA_examples.Olesik_et_al_2020.simulation import Simulation
from MPyDATA_examples.Olesik_et_al_2020.setup import Setup, default_nr, default_GC_max
from MPyDATA_examples.Olesik_et_al_2020.coordinates import x_id, x_log_of_pn, x_p2
from MPyDATA_examples.Olesik_et_al_2020.analysis import compute_figure_data
from MPyDATA.options import Options
import pytest
import numpy as np

setup = Setup()
grid_layout_set = (x_id(), x_p2(), x_log_of_pn(r0=1, n=1))
opt_set = ({
    'n_iters': 1
}, {
    'n_iters': 2,
    'flux_corrected_transport': True
}, {
    'n_iters': 3,
    'third_order_terms': True,
    'infinite_gauge': True,
    'flux_corrected_transport': True
})


@pytest.fixture(scope='module')
def data():
    result, _ = compute_figure_data(nr=default_nr,
                                    GC_max=default_GC_max,
                                    psi_coord=x_id(),
                                    grid_layouts=grid_layout_set,
                                    opt_set=opt_set)
    return result
Esempio n. 6
0
from MPyDATA_examples.Olesik_et_al_2020.coordinates import x_id, x_log_of_pn, x_p2
import pint
import pytest

si = pint.UnitRegistry()


@pytest.mark.parametrize("k", [0, 1, 2, 3])
@pytest.mark.parametrize(
    "coord", [x_id(), x_log_of_pn(r0=1 * si.um, n=1),
              x_p2()])
def test_moment_of_r_integral(k, coord):
    # Arrange
    r0 = 2 * si.um
    r1 = 4 * si.um

    # Act
    integral = coord.moment_of_r_integral(
        coord.x(r1), k) - coord.moment_of_r_integral(coord.x(r0), k)

    # Assert
    if coord.__class__ == x_id:
        assert integral.check(f'[length]**{k+1}')
    elif coord.__class__ == x_p2:
        assert integral.check(f'[length]**{k+2}')
    elif coord.__class__ == x_log_of_pn:
        assert integral.check(f'[length]**{k}')
Esempio n. 7
0
from MPyDATA_examples.Olesik_et_al_2020.simulation import Simulation
from MPyDATA_examples.Olesik_et_al_2020.setup import Setup, default_nr, default_GC_max
from MPyDATA_examples.Olesik_et_al_2020.coordinates import x_id, x_log_of_pn, x_p2
from MPyDATA_examples.Olesik_et_al_2020.analysis import compute_figure_data
from MPyDATA.options import Options
import pytest
import numpy as np

grid_layout_set = (x_id(), x_p2(), x_log_of_pn(n=1))
opt_set = (
    {'n_iters': 1},
    {'n_iters': 2, 'flux_corrected_transport': True},
    {'n_iters': 3, 'third_order_terms': True, 'infinite_gauge': True, 'flux_corrected_transport': True}
)


@pytest.fixture(scope='module')
def data():
    result, _ = compute_figure_data(nr=default_nr, GC_max=default_GC_max, psi_coord=x_id(),
                        grid_layouts=grid_layout_set,
                        opt_set=opt_set)
    return result


@pytest.mark.parametrize("psi_coord", [x_id(), x_p2(), x_log_of_pn(n=1)])
@pytest.mark.parametrize("grid_layout", [x_id(), x_p2(),  x_log_of_pn(n=3)])
@pytest.mark.parametrize("flux_corrected_transport", [False, True])
def test_init(grid_layout, psi_coord, flux_corrected_transport):
    # Arrange
    opts = Options(flux_corrected_transport=flux_corrected_transport)
    setup = Setup()