Water uptake and evaporation after a humidity pulse
View code · Download Python script
Water uptake and evaporation after a humidity pulse
Section titled “Water uptake and evaporation after a humidity pulse”How quickly does a water–organic droplet reverse direction when humid air is replaced by dry air? Follow one homogeneous particle population at 293 K. Water exchanges kinetically with a finite gas reservoir. The generic organic is involatile here. Its BAT descriptors are those of the miscible O:C 0.5 case in Gorkowski et al., Figure 9. The radius, water inventory and gas replacement below define an illustrative experiment. CPU evaluates BAT at each substep. CUDA interpolates a resident table at the same particle compositions.
Python · section 1
import matplotlib.pyplot as pltimport numpy as npfrom matplotlib import style as mplstylefrom particula import Aerosol, plottingfrom particula.dynamics import MassCondensationfrom particula.dynamics.condensation.condensation_strategies import ( CondensationIsothermal,)from particula.dynamics.condensation.species_mapping import ( CondensationSpeciesMap,)from particula.gas import EnvironmentData, GasDatafrom particula.gas.vapor_pressure_strategies import WaterBuckStrategyfrom particula.particles import ActivityBAT, ParticleDatafrom particula.particles.surface_strategies import SurfaceStrategyVolumefrom particula.util.constants import GAS_CONSTANT
TEMPERATURE = 293.0M_WATER = 0.01801528DENSITY = np.array([1000.0, 1243.4933333333333])WATER = WaterBuckStrategy()SAMPLE_INTERVAL = 0.0025 # secondsSAMPLES_PER_LEG = 32
def gas_water(relative_humidity): """Water vapor mass concentration (kg/m³) at the imposed initial RH.""" pressure = WATER.pure_vapor_pressure(TEMPERATURE) return float( relative_humidity * pressure * M_WATER / (GAS_CONSTANT * TEMPERATURE) )
def chamber(): """Represent identical droplets with 1 µm dry organic radius.""" organic = 4 * np.pi / 3 * (1e-6) ** 3 * DENSITY[1] particles = ParticleData( masses=np.array([[[0.12 * organic, organic]]]), concentration=np.array([[1e5]]), volume=np.array([1e-6]), charge=np.zeros((1, 1)), density=DENSITY.copy(), distribution_type="particle_resolved", ) gas = GasData( ["water"], np.array([M_WATER]), np.array([[gas_water(0.90)]]), np.array([True]), ) environment = EnvironmentData([TEMPERATURE], [101325.0], [[0.90]]) process = MassCondensation( CondensationIsothermal( molar_mass=np.array([M_WATER]), diffusion_coefficient=2.4e-5, accommodation_coefficient=0.2, activity_strategy=ActivityBAT(0.2, 0.5, DENSITY[1]), surface_strategy=SurfaceStrategyVolume( density=1000.0, surface_tension=0.072 ), vapor_pressure_strategy=WATER, species_map=CondensationSpeciesMap(("water",), ((0, 0),)), ) ) return Aerosol( particles=particles, gas=gas, environment=environment ), processAccount for the gas replacement
Section titled “Account for the gas replacement”Each leg is closed to water exchange with the surroundings. At 80 ms we replace the water vapor, setting the gas to 35% RH while retaining the particle masses. Two observations at the switch resolve the jump in the gas inventory. Within each leg a change in suspended particle water must be balanced by the opposite vapor change. Both backends take four substeps per outer step. CUDA replays a captured step between observation boundaries.
Python · section 2
def trajectory(device, steps_per_sample): """Return time, wet radius and both water inventories at matched times.""" state, process = chamber() dt = SAMPLE_INTERVAL / steps_per_sample initial_organic = state.particles.masses[0, 0, 1] rows = [] time = 0.0
def record(): snapshot = owner.snapshot() if owner else state np.testing.assert_equal( snapshot.particles.masses[0, 0, 1], initial_organic ) rows.append( [ time, snapshot.particles.radii[0, 0], snapshot.gas.concentration[0, 0], snapshot.particles.species_mass_density[0, 0], ] )
owner = ( process.prepare(state, time_step=dt, device=device) if device else None ) try: if owner: owner.capture() for leg in range(2): if leg: dry = np.array([[gas_water(0.35)]]) if owner: owner.update_gas(dry) else: state.gas.concentration[:] = dry record() for _ in range(SAMPLES_PER_LEG): if owner: owner.run(steps_per_sample) else: for _ in range(steps_per_sample): process.execute(state, time_step=dt, sub_steps=4) time += SAMPLE_INTERVAL record() finally: if owner: owner.close() data = np.array(rows) check_water_budget(data) return data
def check_water_budget(data): """Close each leg independently of the imposed vapor replacement.""" for leg_data in np.split(data, 2): vapor, condensed = leg_data[:, 2:].T np.testing.assert_allclose( vapor - vapor[0], condensed[0] - condensed, rtol=1e-9, atol=1e-15 ) assert ( data[SAMPLES_PER_LEG, 1] > data[0, 1] and data[-1, 1] < data[SAMPLES_PER_LEG + 1, 1] )
def simulate(): """Compare the CUDA trajectory with direct BAT and a finer CPU run.""" direct = trajectory(None, 16) finer = trajectory(None, 32) cuda = trajectory("cuda:0", 16) for other in (direct, cuda): np.testing.assert_allclose(other[:, 1], finer[:, 1], rtol=1e-3, atol=0) error = np.max(np.abs(cuda[:, 1] / finer[:, 1] - 1)) print( f"Maximum CUDA radius difference from refined CPU: {100 * error:.4f}%" ) print( f"CUDA radii before wetting, after wetting, after drying (µm): {1e6 * cuda[[0, SAMPLES_PER_LEG, -1], 1]}" ) return { "cpu": direct.tolist(), "cuda": cuda.tolist(), "refined": finer.tolist(), }Read the radius and water budgets together
Section titled “Read the radius and water budgets together”The radius responds continuously even at the instant of vapor replacement. Plot water in each reservoir as a change from the start of its current leg to resolve the much smaller particle transfer against the absolute gas mass.
Python · section 3
@mplstyle.context("particula.default")def plot_results(result): """Show radius and the equal and opposite changes in water storage.""" fig, axes = plotting.subplots(2, 1, sharex=True, size="wide") for key, style, label in ( ("cpu", "-", "Direct CPU"), ("cuda", "o", "Tabulated CUDA"), ): t, r, vapor, particle = np.array(result[key]).T axes[0].plot( 1000 * t, 1e6 * r, style, label=label, markersize=4, fillstyle="none", ) for i, segment in enumerate(np.array_split(np.arange(len(t)), 2)): for amounts, name, color in ( (vapor, "Vapor", plotting.COLORS["teal"]), (particle, "Particle", plotting.COLORS["rust"]), ): axes[1].plot( 1000 * t[segment], 1e6 * (amounts[segment] - amounts[segment[0]]), style, color=color, markersize=4, fillstyle="none", label=name if key == "cpu" and i == 0 else None, ) for axis in axes: axis.axvline(80, ls=":", color="0.45") plotting.legend(axis) axes[0].set_ylabel("Wet radius (µm)") axes[1].set_ylabel("Water change within leg (mg/m³)") axes[1].set_xlabel("Time (ms)") plotting.fit(fig) return fig
if __name__ == "__main__": result = simulate() plot_results(result) plt.show()Explicit cuda invocation
result = simulate()figure = plot_results(result)plt.show()Warp 1.11.1 initialized:
CUDA Toolkit 12.9, Driver 13.4
Devices:
"cpu" : "CPU"
"cuda:0" : "NVIDIA GeForce RTX 5060" (8 GiB, sm_120, mempool enabled)
Kernel cache:
~/.cache/warp/1.11.1
Module particula.gpu.kernels.condensation 14a649a load on device 'cuda:0' took 1.45 ms (cached)
Module particula.gpu.kernels.condensation 2c7d291 load on device 'cuda:0' took 1.80 ms (cached)
Module particula.gpu.kernels.environment e11375e load on device 'cuda:0' took 1.93 ms (cached)
Module particula.gpu.kernels._condensation_native 34375de load on device 'cuda:0' took 1.97 ms (cached)
Module particula.gpu.kernels.thermodynamics 563d292 load on device 'cuda:0' took 1.64 ms (cached)
Module particula.execution.prepared_guards c5e1f2e load on device 'cuda:0' took 1.55 ms (cached)
Module warp.utils f35afd3 load on device 'cuda:0' took 1.19 ms (cached)
Module warp.math edde159 load on device 'cuda:0' took 2.17 ms (cached)
Module warp.marching_cubes fb6e712 load on device 'cuda:0' took 2.02 ms (cached)
Module particula.gpu.kernels._coagulation_budget b4a3978 load on device 'cuda:0' took 1.64 ms (cached)
Module particula.execution.communication 2909959 load on device 'cuda:0' took 1.45 ms (cached)
Module particula.gpu.kernels._population_validation edde159 load on device 'cuda:0' took 2.16 ms (cached)
Module particula.gpu.kernels.communication ac9b2a2 load on device 'cuda:0' took 2.43 ms (cached)
Module particula.gpu.properties.gas_properties edde159 load on device 'cuda:0' took 2.16 ms (cached)
Module particula.gpu.properties.particle_properties edde159 load on device 'cuda:0' took 2.19 ms (cached)
Module particula.gpu.dynamics.coagulation_funcs edde159 load on device 'cuda:0' took 2.20 ms (cached)
Module particula.gpu.dynamics.condensation_funcs edde159 load on device 'cuda:0' took 2.20 ms (cached)
Module particula.gpu.kernels._condensation_parallel edde159 load on device 'cuda:0' took 2.17 ms (cached)
Module particula.gpu.kernels.exhaustion 616f81d load on device 'cuda:0' took 3.16 ms (cached)
Module particula.gpu.kernels.slot_management 0375e2c load on device 'cuda:0' took 0.87 ms (cached)
Module particula.gpu.kernels.nucleation 1124f09 load on device 'cuda:0' took 2.29 ms (cached)
Module particula.execution.gpu_resources 30f296c load on device 'cuda:0' took 2.01 ms (cached)
Module particula.gpu.warp_types edde159 load on device 'cuda:0' took 2.18 ms (cached)
Module particula.execution.prepared_diagnostics ca06582 load on device 'cuda:0' took 1.83 ms (cached)
Module particula.gpu.kernels.condensation c7ee7df load on device 'cuda:0' took 1.05 ms (cached)
Module particula.gpu.kernels.condensation 57dfed0 load on device 'cuda:0' took 1.31 ms (cached)
Module particula.gpu.kernels.condensation e60be0e load on device 'cuda:0' took 0.81 ms (cached)
Module particula.gpu.kernels._condensation_native 9623455 load on device 'cuda:0' took 3.50 ms (cached)
Module particula.gpu.kernels.condensation 016bbb1 load on device 'cuda:0' took 1.10 ms (cached)
Module particula.gpu.kernels._condensation_native 76403ad load on device 'cuda:0' took 0.97 ms (cached)
Module particula.gpu.kernels.condensation b9ed110 load on device 'cuda:0' took 0.98 ms (cached)
Module particula.gpu.kernels._condensation_native c295a4d load on device 'cuda:0' took 0.95 ms (cached)
Module particula.gpu.kernels._condensation_native a80ebff load on device 'cuda:0' took 2.74 ms (cached)
Module particula.gpu.kernels.condensation c3b7b3c load on device 'cuda:0' took 0.92 ms (cached)
Module particula.gpu.kernels.condensation 328f7a7 load on device 'cuda:0' took 2.95 ms (cached)
Module particula.gpu.kernels.condensation e2db3ba load on device 'cuda:0' took 2.79 ms (cached)
Module particula.gpu.kernels._condensation_native ff4cf87 load on device 'cuda:0' took 3.61 ms (cached)
Maximum CUDA radius difference from refined CPU: 0.0215%
CUDA radii before wetting, after wetting, after drying (µm): [1.04745239 1.17604354 1.02582464]

The wetting and drying legs test the sign and magnitude of the surface pressure driving kinetic exchange. The time scale depends on particle size, gas transport and the available vapor. To explore finite-reservoir effects, vary the represented particle count while holding the initial RH fixed.
Related studies
Section titled “Related studies”Explore this topic: Nonideal mixtures · Population growth and vapor reservoirs