def test_just_do_it(scheme): # Arrange setup = Setup() setup.condensation_scheme = scheme simulation = Simulation(setup) # Act output = simulation.run()
def test_just_do_it(scheme, coord): #, enable_particle_temperatures): # Arrange Setup.total_time = 15 * si.minute setup = Setup() setup.coord = coord #setup.enable_particle_temperatures = enable_particle_temperatures if scheme == 'BDF': setup.dt_max = setup.total_time simulation = Simulation(setup) if scheme == 'BDF': bdf.patch_particles(simulation.particles, setup.coord) # Act output = simulation.run()
def test_wet_vs_dry_spectrum(plot=False): # Arrange setup = Setup() # Act simulation = Simulation(setup) wet_volume = simulation.particles.state['volume'] wet_volume = simulation.particles.backend.to_ndarray(wet_volume) r_wet = phys.radius(volume=wet_volume) / si.nanometre n = simulation.particles.backend.to_ndarray( simulation.particles.state['n']) dry_volume = simulation.particles.state['dry volume'] dry_volume = simulation.particles.backend.to_ndarray(dry_volume) r_dry = phys.radius(volume=dry_volume) / si.nanometre # Plot if plot: plt.plot(r_wet, n) plt.plot(r_dry, n) plt.xscale('log') plt.yscale('log') plt.show() # Assert assert (r_dry < r_wet).all()
def test_dry_spectrum_y(plot=False): setup = Setup() simulation = Simulation(setup) dry_volume = simulation.particles.state['dry volume'] dry_volume = simulation.particles.backend.to_ndarray(dry_volume) rd = phys.radius(volume=dry_volume) / si.nanometre nd = simulation.particles.backend.to_ndarray( simulation.particles.state['n']) dr = (rd[1:] - rd[0:-1]) env = simulation.particles.environment dn_dr = (nd[0:-1] / env.mass_of_dry_air * env["rhod"] / dr) dn_dr /= (1 / si.centimetre**3) if plot: plt.figure(figsize=(5, 5)) plt.xscale('log') plt.yscale('log') plt.xlim(1e1, 1e3) plt.ylim(1e-9, 1e3) plt.yticks(10.**np.arange(-8, 3, step=2)) plt.plot(rd[0:-1], dn_dr) plt.show() # from fig. 1b assert 1e-3 < dn_dr[0] < 1e-2 assert 1e1 < max(dn_dr) < 1e2 assert 0 < dn_dr[-1] < 1e-9
def test_RH(): # Arrange setup = Setup() # Act simulation = Simulation(setup) # Assert assert round(simulation.particles.environment["RH"][0], 3) == 0.856
def test_RH(): # Arrange settings = Settings() # Act simulation = Simulation(settings) # Assert assert round(simulation.core.environment["RH"][0], 3) == 0.856
def test_dry_spectrum_x(): settings = Settings() simulation = Simulation(settings) dry_volume = simulation.core.particles['dry volume'].to_ndarray() rd = phys.radius(volume=dry_volume) / si.nanometre rd = rd[::-1] assert round(rd[1 - 1], 0) == 503 assert round(rd[10 - 1], 0) == 355 assert round(rd[50 - 1], 1) == 75.3 assert round(rd[100 - 1], 1) == 10.8
def test_dry_spectrum_x(): setup = Setup() simulation = Simulation(setup) dry_volume = simulation.particles.state['dry volume'] dry_volume = simulation.particles.backend.to_ndarray(dry_volume) rd = phys.radius(volume=dry_volume) / si.nanometre rd = rd[::-1] assert round(rd[1 - 1], 0) == 503 assert round(rd[10 - 1], 0) == 355 assert round(rd[50 - 1], 1) == 75.3 assert round(rd[100 - 1], 1) == 10.8
def test_displacement(plot=False): # Arrange setup = Setup(n_sd=0) simulation = Simulation(setup) # Act output = simulation.run() # Plot if plot: plt.plot(output["t"], output["S"]) plt.grid() plt.show() # Assert assert np.argmin(output["z"]) == 0 assert output["z"][0] == setup.z0 np.testing.assert_approx_equal(output["z"][-1], 1000) np.testing.assert_approx_equal(np.amax(output["z"]), 1200) assert signal.argrelextrema(np.array(output["z"]), np.greater)[0].shape[0] == 10 assert signal.argrelextrema(np.array(output["z"]), np.less)[0].shape[0] == 10
def test_just_do_it(scheme, coord, adaptive, enable_particle_temperatures): # Arrange if scheme == 'BDF' and not adaptive: return if scheme == 'BDF' and coord == 'volume': return # Setup.total_time = 15 * si.minute setup = Setup(dt_output=10 * si.second) setup.coord = coord setup.adaptive = adaptive setup.enable_particle_temperatures = enable_particle_temperatures if scheme == 'BDF': setup.dt_max = setup.dt_output elif not adaptive: setup.dt_max = 1 * si.second simulation = Simulation(setup) if scheme == 'BDF': bdf.patch_particles(simulation.particles, setup.coord) # Act output = simulation.run() r = np.array(output['r']).T * si.metres n = setup.n / (setup.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 .63 * n_unit < max(N1) < .68 * n_unit assert .14 * n_unit < min(N2) < .15 * n_unit assert .3 * n_unit < max(N2) < .37 * n_unit assert .08 * n_unit < min(N3) < .083 * n_unit assert .27 * n_unit < max(N3) < .4 * n_unit
def test_wet_vs_dry_spectrum(plot=False): # Arrange settings = Settings() # Act simulation = Simulation(settings) wet_volume = simulation.core.particles['volume'].to_ndarray() r_wet = phys.radius(volume=wet_volume) / si.nanometre n = simulation.core.particles['n'].to_ndarray() dry_volume = simulation.core.particles['dry volume'].to_ndarray() r_dry = phys.radius(volume=dry_volume) / si.nanometre # Plot if plot: plt.plot(r_wet, n) plt.plot(r_dry, n) plt.xscale('log') plt.yscale('log') plt.show() # Assert assert (r_dry < r_wet).all()