Skip to content

From a population to an evolving aerosol

Download Python script

What information must be shared before particles and gas can evolve together? An Aerosol holds particle, gas, and environment containers; a process supplies the physical rules. This example first assembles a single-box glycerol state, then uses a separate two-box population to demonstrate dilution and wall loss. You will learn to distinguish stored counts, concentrations, and material mass before interpreting a process result. Read particle construction and gas storage if those quantities are unfamiliar.

Python · section 1
import numpy as np
import particula as par

The vapor-pressure strategy converts a reference pressure and temperature into an initial saturation concentration at 298.15 K. Half of that value is put in the gas container. The retained glycerol parameters are arithmetic demonstration inputs, not a calibrated glycerol property model; the printed concentration should not be used as a reference measurement. The strategy is configuration, not a field stored in GasData.

Python · section 2
molar_mass_glycerol = 92.09382e-3 # kg/mol
parameters_clausius = {
"latent_heat": 71.5 * molar_mass_glycerol,
"latent_heat_units": "J/mol",
"temperature_initial": 125.5,
"temperature_initial_units": "degC",
"pressure_initial": 1,
"pressure_initial_units": "mmHg",
}
vapor_pressure_strategy = par.gas.VaporPressureFactory().get_strategy(
"clausius_clapeyron", parameters_clausius
)
sat_concentration = vapor_pressure_strategy.saturation_concentration(
molar_mass_glycerol, 298.15
)
print(f"Saturation concentration: {sat_concentration:.2e} kg/m^3")
sat_factor = 0.5
glycerol_gas = (
par.gas.GasDataBuilder()
.set_names(["Glycerol"])
.set_molar_mass([molar_mass_glycerol], "kg/mol")
.set_concentration([sat_concentration * sat_factor], "kg/m^3")
.set_partitioning([True])
.build()
)
environment = par.gas.EnvironmentData(
temperature=np.array([298.15]),
pressure=np.array([101325.0]),
saturation_ratio=np.array([[sat_factor]]),
)
Saturation concentration: 4.95e-03 kg/m^3

Discrete bins store number density in m^-3 at reference volume 1 m^3. Each mass lane is per-particle mass in kg, not population mass. The preset retains the original 100 nm mode, geometric spread, and number density.

Python · section 3
particles = par.particles.create_lognormal_binned_particle_data(
distribution_type="discrete",
mode=[100e-9],
geometric_standard_deviation=[1.5],
number_concentration=[1e10], # 1e4 cm^-3
density=1260.0, # 1.26 g/cm^3
)

Partitioning flags distinguish condensable species from inert gas lanes in one ordered gas container. No species list is filtered during construction.

Python · section 4
aerosol = par.Aerosol(
particles=particles, gas=glycerol_gas, environment=environment
)
assert aerosol.particles is particles
assert aerosol.gas is glycerol_gas
assert aerosol.environment is environment
print(aerosol)
print("Number density [m^-3]:", particles.concentration.sum(axis=1))
print(
"Particle mass density [kg/m^3]:",
np.sum(particles.masses * particles.concentration[:, :, None], axis=1),
)
ParticleData(masses=array([[[5.27787566e-24],
        [6.06317521e-24],
        [6.96532014e-24],
        [8.00169597e-24],
        [9.19227503e-24],
        [1.05600013e-23],
        [1.21312328e-23],
        [1.39362491e-23],
        [1.60098353e-23],
        [1.83919522e-23],
        [2.11285062e-23],
        [2.42722344e-23],
        [2.78837205e-23],
        [3.20325627e-23],
        [3.67987146e-23],
        [4.22740262e-23],
        [4.85640141e-23],
        [5.57898945e-23],
        [6.40909197e-23],
        [7.36270615e-23],
        [8.45820938e-23],
        [9.71671345e-23],
        [1.11624714e-22],
        [1.28233449e-22],
        [1.47313411e-22],
        [1.69232298e-22],
        [1.94412513e-22],
        [2.23339314e-22],
        [2.56570158e-22],
        [2.94745448e-22],
        [3.38600870e-22],
        [3.88981578e-22],
        [4.46858474e-22],
        [5.13346921e-22],
        [5.89728241e-22],
        [6.77474401e-22],
        [7.78276385e-22],
        [8.94076782e-22],
        [1.02710722e-21],
        [1.17993136e-21],
        [1.35549434e-21],
        [1.55717948e-21],
        [1.78887352e-21],
        [2.05504152e-21],
        [2.36081287e-21],
        [2.71208020e-21],
        [3.11561289e-21],
        [3.57918755e-21],
        [4.11173787e-21],
        [4.72352680e-21],
        [5.42634431e-21],
        [6.23373464e-21],
        [7.16125725e-21],
        [8.22678673e-21],
        [9.45085723e-21],
        [1.08570582e-20],
        [1.24724890e-20],
        [1.43282811e-20],
        [1.64601981e-20],
        [1.89093248e-20],
        [2.17228591e-20],
        [2.49550216e-20],
        [2.86681002e-20],
        [3.29336509e-20],
        [3.78338764e-20],
        [4.34632107e-20],
        [4.99301383e-20],
        [5.73592855e-20],
        [6.58938217e-20],
        [7.56982188e-20],
        [8.69614203e-20],
        [9.99004830e-20],
        [1.14764760e-19],
        [1.31840705e-19],
        [1.51457394e-19],
        [1.73992867e-19],
        [1.99881411e-19],
        [2.29621934e-19],
        [2.63787575e-19],
        [3.03036750e-19],
        [3.48125842e-19],
        [3.99923778e-19],
        [4.59428773e-19],
        [5.27787566e-19],
        [6.06317521e-19],
        [6.96532014e-19],
        [8.00169597e-19],
        [9.19227503e-19],
        [1.05600013e-18],
        [1.21312328e-18],
        [1.39362491e-18],
        [1.60098353e-18],
        [1.83919522e-18],
        [2.11285062e-18],
        [2.42722344e-18],
        [2.78837205e-18],
        [3.20325627e-18],
        [3.67987146e-18],
        [4.22740262e-18],
        [4.85640141e-18],
        [5.57898945e-18],
        [6.40909197e-18],
        [7.36270615e-18],
        [8.45820938e-18],
        [9.71671345e-18],
        [1.11624714e-17],
        [1.28233449e-17],
        [1.47313411e-17],
        [1.69232298e-17],
        [1.94412513e-17],
        [2.23339314e-17],
        [2.56570158e-17],
        [2.94745448e-17],
        [3.38600870e-17],
        [3.88981578e-17],
        [4.46858474e-17],
        [5.13346921e-17],
        [5.89728241e-17],
        [6.77474401e-17],
        [7.78276385e-17],
        [8.94076782e-17],
        [1.02710722e-16],
        [1.17993136e-16],
        [1.35549434e-16],
        [1.55717948e-16],
        [1.78887352e-16],
        [2.05504152e-16],
        [2.36081287e-16],
        [2.71208020e-16],
        [3.11561289e-16],
        [3.57918755e-16],
        [4.11173787e-16],
        [4.72352680e-16],
        [5.42634431e-16],
        [6.23373464e-16],
        [7.16125725e-16],
        [8.22678673e-16],
        [9.45085723e-16],
        [1.08570582e-15],
        [1.24724890e-15],
        [1.43282811e-15],
        [1.64601981e-15],
        [1.89093248e-15],
        [2.17228591e-15],
        [2.49550216e-15],
        [2.86681002e-15],
        [3.29336509e-15],
        [3.78338764e-15],
        [4.34632107e-15],
        [4.99301383e-15],
        [5.73592855e-15],
        [6.58938217e-15],
        [7.56982188e-15],
        [8.69614203e-15],
        [9.99004830e-15],
        [1.14764760e-14],
        [1.31840705e-14],
        [1.51457394e-14],
        [1.73992867e-14],
        [1.99881411e-14],
        [2.29621934e-14],
        [2.63787575e-14],
        [3.03036750e-14],
        [3.48125842e-14],
        [3.99923778e-14],
        [4.59428773e-14],
        [5.27787566e-14],
        [6.06317521e-14],
        [6.96532014e-14],
        [8.00169597e-14],
        [9.19227503e-14],
        [1.05600013e-13],
        [1.21312328e-13],
        [1.39362491e-13],
        [1.60098353e-13],
        [1.83919522e-13],
        [2.11285062e-13],
        [2.42722344e-13],
        [2.78837205e-13],
        [3.20325627e-13],
        [3.67987146e-13],
        [4.22740262e-13],
        [4.85640141e-13],
        [5.57898945e-13],
        [6.40909197e-13],
        [7.36270615e-13],
        [8.45820938e-13],
        [9.71671345e-13],
        [1.11624714e-12],
        [1.28233449e-12],
        [1.47313411e-12],
        [1.69232298e-12],
        [1.94412513e-12],
        [2.23339314e-12],
        [2.56570158e-12],
        [2.94745448e-12],
        [3.38600870e-12],
        [3.88981578e-12],
        [4.46858474e-12],
        [5.13346921e-12],
        [5.89728241e-12],
        [6.77474401e-12],
        [7.78276385e-12],
        [8.94076782e-12],
        [1.02710722e-11],
        [1.17993136e-11],
        [1.35549434e-11],
        [1.55717948e-11],
        [1.78887352e-11],
        [2.05504152e-11],
        [2.36081287e-11],
        [2.71208020e-11],
        [3.11561289e-11],
        [3.57918755e-11],
        [4.11173787e-11],
        [4.72352680e-11],
        [5.42634431e-11],
        [6.23373464e-11],
        [7.16125725e-11],
        [8.22678673e-11],
        [9.45085723e-11],
        [1.08570582e-10],
        [1.24724890e-10],
        [1.43282811e-10],
        [1.64601981e-10],
        [1.89093248e-10],
        [2.17228591e-10],
        [2.49550216e-10],
        [2.86681002e-10],
        [3.29336509e-10],
        [3.78338764e-10],
        [4.34632107e-10],
        [4.99301383e-10],
        [5.73592855e-10],
        [6.58938217e-10],
        [7.56982188e-10],
        [8.69614203e-10],
        [9.99004830e-10],
        [1.14764760e-09],
        [1.31840705e-09],
        [1.51457394e-09],
        [1.73992867e-09],
        [1.99881411e-09],
        [2.29621934e-09],
        [2.63787575e-09],
        [3.03036750e-09],
        [3.48125842e-09],
        [3.99923778e-09],
        [4.59428773e-09],
        [5.27787566e-09]]]), concentration=array([[4.42885787e-20, 1.60675992e-19, 5.75390670e-19, 2.03388888e-18,
        7.09650006e-18, 2.44407079e-17, 8.30875455e-17, 2.78811485e-16,
        9.23502278e-16, 3.01938062e-15, 9.74429304e-15, 3.10409775e-14,
        9.76052153e-14, 3.02944616e-13, 9.28124067e-13, 2.80673501e-12,
        8.37817386e-12, 2.46859535e-11, 7.17964590e-11, 2.06114585e-10,
        5.84072832e-10, 1.63372091e-09, 4.51067263e-09, 1.22929844e-08,
        3.30693711e-08, 8.78106353e-08, 2.30155249e-07, 5.95452647e-07,
        1.52063911e-06, 3.83316633e-06, 9.53765815e-06, 2.34249364e-05,
        5.67894511e-05, 1.35896885e-04, 3.20999172e-04, 7.48429512e-04,
        1.72246528e-03, 3.91293497e-03, 8.77419668e-03, 1.94206911e-02,
        4.24301509e-02, 9.15033623e-02, 1.94783475e-01, 4.09279270e-01,
        8.48867618e-01, 1.73785191e+00, 3.51186770e+00, 7.00512853e+00,
        1.37926162e+01, 2.68058617e+01, 5.14239551e+01, 9.73764103e+01,
        1.82009738e+02, 3.35805706e+02, 6.11552996e+02, 1.09934171e+03,
        1.95067040e+03, 3.41654907e+03, 5.90668773e+03, 1.00798238e+04,
        1.69790917e+04, 2.82311484e+04, 4.63335118e+04, 7.50610217e+04,
        1.20029033e+05, 1.89457028e+05, 2.95180536e+05, 4.53959693e+05,
        6.89127293e+05, 1.03260492e+06, 1.52729000e+06, 2.22977688e+06,
        3.21331934e+06, 4.57087083e+06, 6.41795386e+06, 8.89501763e+06,
        1.21688522e+07, 1.64325515e+07, 2.19034722e+07, 2.88186420e+07,
        3.74271397e+07, 4.79791275e+07, 6.07114540e+07, 7.58300780e+07,
        9.34899553e+07, 1.13773464e+08, 1.36668867e+08, 1.62050653e+08,
        1.89663848e+08, 2.19114396e+08, 2.49867543e+08, 2.81255718e+08,
        3.12496715e+08, 3.42722118e+08, 3.71014934e+08, 3.96454388e+08,
        4.18164969e+08, 4.35366138e+08, 4.47418799e+08, 4.53864682e+08,
        4.54455256e+08, 4.49167633e+08, 4.38206038e+08, 4.21988719e+08,
        4.01121468e+08, 3.76360080e+08, 3.48565001e+08, 3.18651954e+08,
        2.87542453e+08, 2.56117906e+08, 2.25180351e+08, 1.95422076e+08,
        1.67405350e+08, 1.41552527e+08, 1.18145857e+08, 9.73356541e+07,
        7.91549331e+07, 6.35384478e+07, 5.03440091e+07, 3.93741846e+07,
        3.03968045e+07, 2.31631100e+07, 1.74228175e+07, 1.29357760e+07,
        9.48023641e+06, 6.85801497e+06, 4.89700188e+06, 3.45155417e+06,
        2.40132917e+06, 1.64907832e+06, 1.11784978e+06, 7.47959688e+05,
        4.93998373e+05, 3.22051574e+05, 2.07242066e+05, 1.31638517e+05,
        8.25354706e+04, 5.10799969e+04, 3.12042446e+04, 1.88160763e+04,
        1.11994588e+04, 6.57987421e+03, 3.81584500e+03, 2.18432090e+03,
        1.23422613e+03, 6.88375830e+02, 3.78973699e+02, 2.05942086e+02,
        1.10467297e+02, 5.84890984e+01, 3.05681184e+01, 1.57693963e+01,
        8.02997161e+00, 4.03613359e+00, 2.00248668e+00, 9.80677746e-01,
        4.74062481e-01, 2.26202516e-01, 1.06539795e-01, 4.95312017e-02,
        2.27299486e-02, 1.02960495e-02, 4.60357657e-03, 2.03176138e-03,
        8.85120934e-04, 3.80614303e-04, 1.61554916e-04, 6.76873997e-05,
        2.79929111e-05, 1.14272277e-05, 4.60454027e-06, 1.83140439e-06,
        7.19009799e-07, 2.78636462e-07, 1.06584405e-07, 4.02440765e-08,
        1.49990187e-08, 5.51793153e-09, 2.00374453e-09, 7.18225750e-10,
        2.54116096e-10, 8.87474655e-11, 3.05937226e-11, 1.04102527e-11,
        3.49657458e-12, 1.15924946e-12, 3.79370530e-13, 1.22547050e-13,
        3.90746152e-14, 1.22981317e-14, 3.82064029e-15, 1.17161721e-15,
        3.54640161e-16, 1.05960176e-16, 3.12499987e-17, 9.09724557e-18,
        2.61410131e-18, 7.41459596e-19, 2.07589388e-19, 5.73687498e-20,
        1.56494185e-20, 4.21379695e-21, 1.11995761e-21, 2.93820535e-22,
        7.60878456e-23, 1.94491672e-23, 4.90726276e-24, 1.22216600e-24,
        3.00451006e-25, 7.29070806e-26, 1.74629791e-26, 4.12875908e-27,
        9.63547946e-28, 2.21962546e-28, 5.04706210e-29, 1.13279201e-29,
        2.50965654e-30, 5.48821329e-31, 1.18467781e-31, 2.52419038e-32,
        5.30880217e-33, 1.10210648e-33, 2.25841189e-34, 4.56809712e-35,
        9.12053020e-36, 1.79745251e-36, 3.49661119e-37, 6.71413149e-38,
        1.27257950e-38, 2.38085301e-39, 4.39676066e-40, 8.01467005e-41,
        1.44208564e-41, 2.56123269e-42, 4.49013709e-43, 7.77003090e-44,
        1.32720642e-44, 2.23772534e-45, 3.72415431e-46, 6.11788257e-47,
        9.92035437e-48, 1.58783663e-48, 2.50863240e-49, 3.91219793e-50,
        6.02222797e-51, 9.15052781e-52, 1.37242203e-52, 2.03180392e-53,
        2.96912506e-54, 4.28279973e-55]]), charge=array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]), density=array([1260.]), volume=array([1.]), distribution_type='discrete', radius_grid=None)
GasData(name=['Glycerol'], molar_mass=array([0.09209382]), concentration=array([[0.00247482]]), partitioning=array([ True]))
EnvironmentData(temperature=array([298.15]), pressure=array([101325.]), saturation_ratio=array([[0.5]]))
Number density [m^-3]: [1.e+10]
Particle mass density [kg/m^3]: [[1.10599721e-07]]

The identity assertions show that assembly holds the supplied containers. Consequently, editing a held array edits the aerosol. A detached copy() is needed for a control case. The printed number and mass densities describe the initialized population; no glycerol condensation step has been executed.

Compare two boxes under the same dilution law

Section titled “Compare two boxes under the same dilution law”

The next population is particle-resolved, so its weights are represented counts. The boxes have different counts and volumes (0.25 and 4 m³); equal raw weights would therefore not imply equal number densities. Dilution at 0.1 s⁻¹ over 2 s multiplies each inventory by exp(−0.2). The assertions compare with that analytic factor, while rate returns slot number-density rates in m⁻³ s⁻¹.

This gives a useful controlled comparison: the fractional change is the same in both boxes even though their absolute concentrations differ.

Python · section 5
box_particles = par.particles.create_resolved_particle_data(
masses=np.array([[[1e-18], [2e-18]], [[1e-18], [2e-18]]]),
density=1000.0,
concentration=np.array([[10.0, 20.0], [30.0, 40.0]]),
volume=np.array([0.25, 4.0]),
)
box_gas = (
par.gas.GasDataBuilder()
.set_names(["inert"])
.set_molar_mass([0.028])
.set_concentration([[1e-6], [2e-6]])
.set_partitioning([False])
.build()
)
box_aerosol = par.Aerosol(
particles=box_particles,
gas=box_gas,
environment=par.gas.EnvironmentData(
[280.0, 310.0], [101325.0, 90000.0], [[0.0], [0.0]]
),
)
dilution = par.dynamics.Dilution(par.dynamics.DilutionStrategy(0.1))
initial_counts = box_particles.concentration.copy()
initial_gas = box_gas.concentration.copy()
box_rates = dilution.rate(box_aerosol)
assert box_rates.shape == (2, 2)
np.testing.assert_allclose(
box_rates, -0.1 * initial_counts / box_particles.volume[:, None]
)
assert dilution.execute(box_aerosol, time_step=2.0, sub_steps=2) is box_aerosol
np.testing.assert_allclose(
box_particles.concentration, initial_counts * np.exp(-0.2)
)
np.testing.assert_allclose(box_gas.concentration, initial_gas * np.exp(-0.2))
print(
"Two-box number densities after dilution [m^-3]:",
box_particles.number_density,
)
print("Runnable rate shape (boxes, slots):", box_rates.shape)
Two-box number densities after dilution [m^-3]: [98.24769037 14.32778818]
Runnable rate shape (boxes, slots): (2, 2)

Spherical wall loss now acts on the diluted population. Stable logical box IDs keep random streams associated with the boxes. Reuse the context to continue those streams; a seed is not a request to restart them on every call. The printed post-loss densities describe this realization, not an ensemble-average loss law.

Python · section 6
context = par.CPUExecutionContext(
root_seed=42, box_ids=("chamber-a", "chamber-b")
)
wall_loss = par.dynamics.WallLoss(
par.dynamics.SphericalWallLossStrategy(
wall_eddy_diffusivity=0.001,
chamber_radius=0.5,
distribution_type="particle_resolved",
)
)
wall_loss.execute(box_aerosol, time_step=0.1, context=context)
print("Per-box volumes [m^3]:", box_particles.volume)
print("Number densities after wall loss [m^-3]:", box_particles.number_density)
Per-box volumes [m^3]: [0.25 4.  ]
Number densities after wall loss [m^-3]: [98.24769037 14.32778818]

What the assembled state lets you investigate

Section titled “What the assembled state lets you investigate”

The example separates three questions: what is stored, how a deterministic process changes it, and how a stochastic step samples change. The dilution assertions support the specified exponential decay; they do not validate the wall-loss model or the illustrative glycerol parameters.

For a chamber comparison, vary physical volume while preserving initial number density, then compare normalized losses across repeated wall-loss realizations. That requires adjusting represented counts and checking material inventories, not merely changing volume. Continue with state access and replacement or the wall-loss examples.

Explore this topic: Constructing aerosol state