PySDM_examples.Arabas_et_al_2023.make_particulator
1import numpy as np 2 3from PySDM import Builder, Formulae 4from PySDM import products as PySDM_products 5from PySDM.backends import CPU 6from PySDM.dynamics import Freezing 7from PySDM.environments import Box 8from PySDM.initialisation.sampling.spectro_glacial_sampling import ( 9 SpectroGlacialSampling, 10) 11 12A_VALUE_LARGER_THAN_ONE = 44 13 14 15def make_particulator( 16 *, 17 constants, 18 n_sd, 19 dt, 20 initial_temperature, 21 singular, 22 seed, 23 shima_T_fz, 24 ABIFM_spec, 25 droplet_volume, 26 total_particle_number, 27 volume, 28 thaw=False 29): 30 attributes = {"volume": np.ones(n_sd) * droplet_volume} 31 32 formulae_ctor_args = { 33 "seed": seed, 34 "constants": constants, 35 "freezing_temperature_spectrum": shima_T_fz, 36 "heterogeneous_ice_nucleation_rate": "ABIFM", 37 "particle_shape_and_density": "MixedPhaseSpheres", 38 } 39 formulae = Formulae(**formulae_ctor_args) 40 backend = CPU(formulae, override_jit_flags={"parallel": False}) 41 42 sampling = SpectroGlacialSampling( 43 freezing_temperature_spectrum=formulae.freezing_temperature_spectrum, 44 insoluble_surface_spectrum=ABIFM_spec, 45 ) 46 if singular: 47 ( 48 attributes["freezing temperature"], 49 _, 50 attributes["multiplicity"], 51 ) = sampling.sample(backend=backend, n_sd=n_sd) 52 else: 53 ( 54 _, 55 attributes["immersed surface area"], 56 attributes["multiplicity"], 57 ) = sampling.sample(backend=backend, n_sd=n_sd) 58 attributes["multiplicity"] *= total_particle_number 59 60 builder = Builder(n_sd=n_sd, backend=backend, environment=Box(dt, volume)) 61 62 env = builder.particulator.environment 63 env["T"] = initial_temperature 64 env["RH"] = A_VALUE_LARGER_THAN_ONE 65 env["rhod"] = 1.0 66 67 builder.add_dynamic(Freezing(singular=singular, thaw=thaw)) 68 69 return builder.build( 70 attributes=attributes, 71 products=( 72 PySDM_products.Time(name="t"), 73 PySDM_products.AmbientTemperature(name="T"), 74 PySDM_products.SpecificIceWaterContent(name="qi"), 75 ), 76 )
A_VALUE_LARGER_THAN_ONE =
44
def
make_particulator( *, constants, n_sd, dt, initial_temperature, singular, seed, shima_T_fz, ABIFM_spec, droplet_volume, total_particle_number, volume, thaw=False):
16def make_particulator( 17 *, 18 constants, 19 n_sd, 20 dt, 21 initial_temperature, 22 singular, 23 seed, 24 shima_T_fz, 25 ABIFM_spec, 26 droplet_volume, 27 total_particle_number, 28 volume, 29 thaw=False 30): 31 attributes = {"volume": np.ones(n_sd) * droplet_volume} 32 33 formulae_ctor_args = { 34 "seed": seed, 35 "constants": constants, 36 "freezing_temperature_spectrum": shima_T_fz, 37 "heterogeneous_ice_nucleation_rate": "ABIFM", 38 "particle_shape_and_density": "MixedPhaseSpheres", 39 } 40 formulae = Formulae(**formulae_ctor_args) 41 backend = CPU(formulae, override_jit_flags={"parallel": False}) 42 43 sampling = SpectroGlacialSampling( 44 freezing_temperature_spectrum=formulae.freezing_temperature_spectrum, 45 insoluble_surface_spectrum=ABIFM_spec, 46 ) 47 if singular: 48 ( 49 attributes["freezing temperature"], 50 _, 51 attributes["multiplicity"], 52 ) = sampling.sample(backend=backend, n_sd=n_sd) 53 else: 54 ( 55 _, 56 attributes["immersed surface area"], 57 attributes["multiplicity"], 58 ) = sampling.sample(backend=backend, n_sd=n_sd) 59 attributes["multiplicity"] *= total_particle_number 60 61 builder = Builder(n_sd=n_sd, backend=backend, environment=Box(dt, volume)) 62 63 env = builder.particulator.environment 64 env["T"] = initial_temperature 65 env["RH"] = A_VALUE_LARGER_THAN_ONE 66 env["rhod"] = 1.0 67 68 builder.add_dynamic(Freezing(singular=singular, thaw=thaw)) 69 70 return builder.build( 71 attributes=attributes, 72 products=( 73 PySDM_products.Time(name="t"), 74 PySDM_products.AmbientTemperature(name="T"), 75 PySDM_products.SpecificIceWaterContent(name="qi"), 76 ), 77 )