|
| 1 | +from PySDM_examples.Alpert_and_Knopf_2016 import simulation, Table1 |
| 2 | +from PySDM.physics import si, constants as const, Formulae |
| 3 | +from PySDM.physics.spectra import Lognormal |
| 4 | +import numpy as np |
| 5 | +from matplotlib import pylab |
| 6 | +import pytest |
| 7 | + |
| 8 | +n_runs_per_case = 3 |
| 9 | + |
| 10 | +@pytest.mark.parametrize("multiplicity", (1, 2, 10)) |
| 11 | +def test_AK16_fig_1(multiplicity, plot=False): |
| 12 | + # Arrange |
| 13 | + J_het = 1e3 / si.cm ** 2 / si.s |
| 14 | + A_g = 1e-5 * si.cm ** 2 |
| 15 | + |
| 16 | + dt = 1 * si.s |
| 17 | + total_time = 6 * si.min |
| 18 | + |
| 19 | + # dummy multipliers (multiplied and then divided by) |
| 20 | + dv = 1 * si.cm ** 3 # will become used if coalescence or other processes are turned on |
| 21 | + droplet_volume = 1 * si.um ** 3 # ditto |
| 22 | + |
| 23 | + cases = Table1(dv=dv) |
| 24 | + |
| 25 | + # Act |
| 26 | + output = {} |
| 27 | + |
| 28 | + for key in ('Iso3', 'Iso4', 'Iso1', 'Iso2'): |
| 29 | + case = cases[key] |
| 30 | + output[key] = [] |
| 31 | + for i in range(n_runs_per_case): |
| 32 | + seed = i |
| 33 | + number_of_real_droplets = case['ISA'].norm_factor * dv |
| 34 | + n_sd = number_of_real_droplets / multiplicity |
| 35 | + assert int(n_sd) == n_sd |
| 36 | + n_sd = int(n_sd) |
| 37 | + |
| 38 | + data = simulation(seed=i, n_sd=n_sd, dt=dt, dv=dv, spectrum=case['ISA'], |
| 39 | + droplet_volume=droplet_volume, multiplicity=multiplicity, J_het=J_het, |
| 40 | + total_time=total_time, number_of_real_droplets=number_of_real_droplets) |
| 41 | + output[key].append(data) |
| 42 | + |
| 43 | + # Plot |
| 44 | + if plot: |
| 45 | + for key in output.keys(): |
| 46 | + for run in range(n_runs_per_case): |
| 47 | + label = f"{key}: σ=ln({int(cases[key]['ISA'].s_geom)}),N={int(cases[key]['ISA'].norm_factor * dv)}" |
| 48 | + pylab.step( |
| 49 | + dt / si.min * np.arange(len(output[key][run])), |
| 50 | + output[key][run], |
| 51 | + label=label if run == 0 else None, |
| 52 | + color=cases[key]['color'], |
| 53 | + linewidth=.666 |
| 54 | + ) |
| 55 | + output[key].append(np.mean(np.asarray(output[key]), axis=0)) |
| 56 | + pylab.step( |
| 57 | + dt / si.min * np.arange(len(output[key][-1])), |
| 58 | + output[key][-1], |
| 59 | + color=cases[key]['color'], |
| 60 | + linewidth=1.666 |
| 61 | + ) |
| 62 | + |
| 63 | + pylab.legend() |
| 64 | + pylab.yscale('log') |
| 65 | + pylab.ylim(1e-2, 1) |
| 66 | + pylab.xlim(0, total_time / si.min) |
| 67 | + pylab.xlabel("t / min") |
| 68 | + pylab.ylabel("$f_{ufz}$") |
| 69 | + pylab.gca().set_box_aspect(1) |
| 70 | + pylab.show() |
| 71 | + |
| 72 | + # Assert |
| 73 | + np.testing.assert_array_less( |
| 74 | + output['Iso3'][-1][1:int(1 * si.min / dt)], |
| 75 | + output['Iso1'][-1][1:int(1 * si.min / dt)] |
| 76 | + ) |
| 77 | + np.testing.assert_array_less( |
| 78 | + output['Iso1'][-1][int(2 * si.min / dt):], |
| 79 | + output['Iso3'][-1][int(2 * si.min / dt):] |
| 80 | + ) |
| 81 | + np.testing.assert_array_less( |
| 82 | + output['Iso2'][int(.5 * si.min / dt):], |
| 83 | + output['Iso1'][int(.5 * si.min / dt):] |
| 84 | + ) |
| 85 | + for key in output.keys(): |
| 86 | + np.testing.assert_array_less(1e-3, output[key][-1][:int(.25 * si.min / dt)]) |
| 87 | + np.testing.assert_array_less(output[key][-1][:], 1 + 1e-10) |
0 commit comments