PySDM_examples.Abade_and_Albuquerque_2024.simulation
1import numpy as np 2 3from PySDM_examples.utils import BasicSimulation 4 5from PySDM import Builder 6from PySDM.backends import CPU 7from PySDM.dynamics import Condensation, AmbientThermodynamics 8from PySDM.initialisation.sampling.spectral_sampling import ConstantMultiplicity 9from PySDM.products import AmbientTemperature, ParcelDisplacement, WaterMixingRatio 10from PySDM.environments import Parcel 11 12 13class Simulation(BasicSimulation): 14 def __init__(self, settings): 15 builder = Builder( 16 backend=CPU(settings.formulae, override_jit_flags={"parallel": False}), 17 n_sd=settings.n_sd, 18 environment=Parcel( 19 dt=settings.timestep, 20 mass_of_dry_air=settings.mass_of_dry_air, 21 p0=settings.initial_total_pressure, 22 initial_water_vapour_mixing_ratio=settings.initial_water_vapour_mixing_ratio, 23 T0=settings.initial_temperature, 24 w=settings.updraft, 25 ), 26 ) 27 builder.add_dynamic(AmbientThermodynamics()) 28 builder.add_dynamic(Condensation()) 29 30 r_dry, n_in_dv = ConstantMultiplicity(settings.soluble_aerosol).sample( 31 n_sd=settings.n_sd 32 ) 33 attributes = builder.particulator.environment.init_attributes( 34 n_in_dv=n_in_dv, kappa=settings.kappa, r_dry=r_dry 35 ) 36 self.products = ( 37 WaterMixingRatio(name="water", radius_range=(0, np.inf)), 38 WaterMixingRatio(name="ice", radius_range=(-np.inf, 0)), 39 WaterMixingRatio(name="total", radius_range=(-np.inf, np.inf)), 40 ParcelDisplacement(name="height"), 41 AmbientTemperature(name="T"), 42 ) 43 super().__init__( 44 particulator=builder.build(attributes=attributes, products=self.products) 45 ) 46 47 def run(self, *, nt, steps_per_output_interval): 48 return self._run(nt=nt, steps_per_output_interval=steps_per_output_interval)
14class Simulation(BasicSimulation): 15 def __init__(self, settings): 16 builder = Builder( 17 backend=CPU(settings.formulae, override_jit_flags={"parallel": False}), 18 n_sd=settings.n_sd, 19 environment=Parcel( 20 dt=settings.timestep, 21 mass_of_dry_air=settings.mass_of_dry_air, 22 p0=settings.initial_total_pressure, 23 initial_water_vapour_mixing_ratio=settings.initial_water_vapour_mixing_ratio, 24 T0=settings.initial_temperature, 25 w=settings.updraft, 26 ), 27 ) 28 builder.add_dynamic(AmbientThermodynamics()) 29 builder.add_dynamic(Condensation()) 30 31 r_dry, n_in_dv = ConstantMultiplicity(settings.soluble_aerosol).sample( 32 n_sd=settings.n_sd 33 ) 34 attributes = builder.particulator.environment.init_attributes( 35 n_in_dv=n_in_dv, kappa=settings.kappa, r_dry=r_dry 36 ) 37 self.products = ( 38 WaterMixingRatio(name="water", radius_range=(0, np.inf)), 39 WaterMixingRatio(name="ice", radius_range=(-np.inf, 0)), 40 WaterMixingRatio(name="total", radius_range=(-np.inf, np.inf)), 41 ParcelDisplacement(name="height"), 42 AmbientTemperature(name="T"), 43 ) 44 super().__init__( 45 particulator=builder.build(attributes=attributes, products=self.products) 46 ) 47 48 def run(self, *, nt, steps_per_output_interval): 49 return self._run(nt=nt, steps_per_output_interval=steps_per_output_interval)
Simulation(settings)
15 def __init__(self, settings): 16 builder = Builder( 17 backend=CPU(settings.formulae, override_jit_flags={"parallel": False}), 18 n_sd=settings.n_sd, 19 environment=Parcel( 20 dt=settings.timestep, 21 mass_of_dry_air=settings.mass_of_dry_air, 22 p0=settings.initial_total_pressure, 23 initial_water_vapour_mixing_ratio=settings.initial_water_vapour_mixing_ratio, 24 T0=settings.initial_temperature, 25 w=settings.updraft, 26 ), 27 ) 28 builder.add_dynamic(AmbientThermodynamics()) 29 builder.add_dynamic(Condensation()) 30 31 r_dry, n_in_dv = ConstantMultiplicity(settings.soluble_aerosol).sample( 32 n_sd=settings.n_sd 33 ) 34 attributes = builder.particulator.environment.init_attributes( 35 n_in_dv=n_in_dv, kappa=settings.kappa, r_dry=r_dry 36 ) 37 self.products = ( 38 WaterMixingRatio(name="water", radius_range=(0, np.inf)), 39 WaterMixingRatio(name="ice", radius_range=(-np.inf, 0)), 40 WaterMixingRatio(name="total", radius_range=(-np.inf, np.inf)), 41 ParcelDisplacement(name="height"), 42 AmbientTemperature(name="T"), 43 ) 44 super().__init__( 45 particulator=builder.build(attributes=attributes, products=self.products) 46 )