PySDM_examples.Luettmer_homogeneous_freezing.settings
prepare settings for simulations for homogeneous freezing notebooks
1"""prepare settings for simulations for homogeneous freezing notebooks""" 2 3import numpy as np 4from PySDM.physics.constants import si 5from PySDM.initialisation.spectra import Lognormal 6from PySDM.initialisation.sampling import spectral_sampling 7 8 9class Settings: 10 def __init__( 11 self, 12 *, 13 hom_freezing: str, 14 n_sd: int, 15 w_updraft: float, 16 T0: float, 17 dz: float, 18 n_ccn: float, 19 r_ccn: float, 20 sigma_droplet_distribution: float = None, 21 type_droplet_distribution: str, 22 p0: float = 200 * si.hectopascals, 23 RH_0: float = 1.0, 24 kappa: float = 0.64, 25 deposition_enable: bool = True, 26 silent: bool = True, 27 n_output: int = 30, 28 backend=None, 29 number_of_ensemble_runs=1, 30 t_max_duration=10000, 31 ): 32 self.backend = backend 33 if not silent: 34 print( 35 "Setting up simulation for " 36 + hom_freezing 37 + " with wpdraft=" 38 + str(w_updraft) 39 + " and N_sd=" 40 + str(n_sd) 41 + " and n_ccn=" 42 + str(n_ccn) 43 ) 44 self.n_sd = n_sd 45 self.w_updraft = w_updraft 46 self.n_ccn = n_ccn 47 self.r_ccn = r_ccn 48 self.sigma_droplet_distribution = sigma_droplet_distribution 49 self.type_droplet_distribution = type_droplet_distribution 50 self.mass_of_dry_air = 1000 * si.kilogram 51 self.initial_pressure = p0 52 self.initial_water_supersaturation = RH_0 53 self.kappa = kappa 54 self.initial_temperature = T0 55 self.deposition_enable = deposition_enable 56 self.silent = silent 57 58 if hom_freezing == "threshold": 59 self.hom_freezing_type = "threshold" 60 else: 61 self.hom_freezing_type = "time-dependent" 62 63 self.formulae = backend.formulae 64 65 const = self.formulae.constants 66 pvs_w = self.formulae.saturation_vapour_pressure.pvs_water( 67 self.initial_temperature 68 ) 69 self.initial_water_vapour_mixing_ratio = const.eps / ( 70 self.initial_pressure / self.initial_water_supersaturation / pvs_w - 1 71 ) 72 dry_air_density = ( 73 self.formulae.trivia.p_d( 74 const.p_STP, self.initial_water_vapour_mixing_ratio 75 ) 76 / const.T_STP 77 / const.Rd 78 ) 79 80 if self.type_droplet_distribution == ("monodisperse"): 81 self.r_wet = np.ones(self.n_sd) * r_ccn 82 self.specific_concentration = ( 83 np.ones(self.n_sd) * n_ccn / self.n_sd / dry_air_density 84 ) 85 elif self.type_droplet_distribution == ("lognormal"): 86 spectrum = Lognormal( 87 norm_factor=n_ccn / dry_air_density, 88 m_mode=r_ccn, 89 s_geom=sigma_droplet_distribution, 90 ) 91 self.r_wet, self.specific_concentration = spectral_sampling.Logarithmic( 92 spectrum 93 ).sample_deterministic(n_sd) 94 95 self.number_of_ensemble_runs = number_of_ensemble_runs 96 self.dz = dz 97 self.t_max_duration = t_max_duration 98 self.dt = dz / self.w_updraft 99 self.n_output = n_output
class
Settings:
10class Settings: 11 def __init__( 12 self, 13 *, 14 hom_freezing: str, 15 n_sd: int, 16 w_updraft: float, 17 T0: float, 18 dz: float, 19 n_ccn: float, 20 r_ccn: float, 21 sigma_droplet_distribution: float = None, 22 type_droplet_distribution: str, 23 p0: float = 200 * si.hectopascals, 24 RH_0: float = 1.0, 25 kappa: float = 0.64, 26 deposition_enable: bool = True, 27 silent: bool = True, 28 n_output: int = 30, 29 backend=None, 30 number_of_ensemble_runs=1, 31 t_max_duration=10000, 32 ): 33 self.backend = backend 34 if not silent: 35 print( 36 "Setting up simulation for " 37 + hom_freezing 38 + " with wpdraft=" 39 + str(w_updraft) 40 + " and N_sd=" 41 + str(n_sd) 42 + " and n_ccn=" 43 + str(n_ccn) 44 ) 45 self.n_sd = n_sd 46 self.w_updraft = w_updraft 47 self.n_ccn = n_ccn 48 self.r_ccn = r_ccn 49 self.sigma_droplet_distribution = sigma_droplet_distribution 50 self.type_droplet_distribution = type_droplet_distribution 51 self.mass_of_dry_air = 1000 * si.kilogram 52 self.initial_pressure = p0 53 self.initial_water_supersaturation = RH_0 54 self.kappa = kappa 55 self.initial_temperature = T0 56 self.deposition_enable = deposition_enable 57 self.silent = silent 58 59 if hom_freezing == "threshold": 60 self.hom_freezing_type = "threshold" 61 else: 62 self.hom_freezing_type = "time-dependent" 63 64 self.formulae = backend.formulae 65 66 const = self.formulae.constants 67 pvs_w = self.formulae.saturation_vapour_pressure.pvs_water( 68 self.initial_temperature 69 ) 70 self.initial_water_vapour_mixing_ratio = const.eps / ( 71 self.initial_pressure / self.initial_water_supersaturation / pvs_w - 1 72 ) 73 dry_air_density = ( 74 self.formulae.trivia.p_d( 75 const.p_STP, self.initial_water_vapour_mixing_ratio 76 ) 77 / const.T_STP 78 / const.Rd 79 ) 80 81 if self.type_droplet_distribution == ("monodisperse"): 82 self.r_wet = np.ones(self.n_sd) * r_ccn 83 self.specific_concentration = ( 84 np.ones(self.n_sd) * n_ccn / self.n_sd / dry_air_density 85 ) 86 elif self.type_droplet_distribution == ("lognormal"): 87 spectrum = Lognormal( 88 norm_factor=n_ccn / dry_air_density, 89 m_mode=r_ccn, 90 s_geom=sigma_droplet_distribution, 91 ) 92 self.r_wet, self.specific_concentration = spectral_sampling.Logarithmic( 93 spectrum 94 ).sample_deterministic(n_sd) 95 96 self.number_of_ensemble_runs = number_of_ensemble_runs 97 self.dz = dz 98 self.t_max_duration = t_max_duration 99 self.dt = dz / self.w_updraft 100 self.n_output = n_output
Settings( *, hom_freezing: str, n_sd: int, w_updraft: float, T0: float, dz: float, n_ccn: float, r_ccn: float, sigma_droplet_distribution: float = None, type_droplet_distribution: str, p0: float = 20000.0, RH_0: float = 1.0, kappa: float = 0.64, deposition_enable: bool = True, silent: bool = True, n_output: int = 30, backend=None, number_of_ensemble_runs=1, t_max_duration=10000)
11 def __init__( 12 self, 13 *, 14 hom_freezing: str, 15 n_sd: int, 16 w_updraft: float, 17 T0: float, 18 dz: float, 19 n_ccn: float, 20 r_ccn: float, 21 sigma_droplet_distribution: float = None, 22 type_droplet_distribution: str, 23 p0: float = 200 * si.hectopascals, 24 RH_0: float = 1.0, 25 kappa: float = 0.64, 26 deposition_enable: bool = True, 27 silent: bool = True, 28 n_output: int = 30, 29 backend=None, 30 number_of_ensemble_runs=1, 31 t_max_duration=10000, 32 ): 33 self.backend = backend 34 if not silent: 35 print( 36 "Setting up simulation for " 37 + hom_freezing 38 + " with wpdraft=" 39 + str(w_updraft) 40 + " and N_sd=" 41 + str(n_sd) 42 + " and n_ccn=" 43 + str(n_ccn) 44 ) 45 self.n_sd = n_sd 46 self.w_updraft = w_updraft 47 self.n_ccn = n_ccn 48 self.r_ccn = r_ccn 49 self.sigma_droplet_distribution = sigma_droplet_distribution 50 self.type_droplet_distribution = type_droplet_distribution 51 self.mass_of_dry_air = 1000 * si.kilogram 52 self.initial_pressure = p0 53 self.initial_water_supersaturation = RH_0 54 self.kappa = kappa 55 self.initial_temperature = T0 56 self.deposition_enable = deposition_enable 57 self.silent = silent 58 59 if hom_freezing == "threshold": 60 self.hom_freezing_type = "threshold" 61 else: 62 self.hom_freezing_type = "time-dependent" 63 64 self.formulae = backend.formulae 65 66 const = self.formulae.constants 67 pvs_w = self.formulae.saturation_vapour_pressure.pvs_water( 68 self.initial_temperature 69 ) 70 self.initial_water_vapour_mixing_ratio = const.eps / ( 71 self.initial_pressure / self.initial_water_supersaturation / pvs_w - 1 72 ) 73 dry_air_density = ( 74 self.formulae.trivia.p_d( 75 const.p_STP, self.initial_water_vapour_mixing_ratio 76 ) 77 / const.T_STP 78 / const.Rd 79 ) 80 81 if self.type_droplet_distribution == ("monodisperse"): 82 self.r_wet = np.ones(self.n_sd) * r_ccn 83 self.specific_concentration = ( 84 np.ones(self.n_sd) * n_ccn / self.n_sd / dry_air_density 85 ) 86 elif self.type_droplet_distribution == ("lognormal"): 87 spectrum = Lognormal( 88 norm_factor=n_ccn / dry_air_density, 89 m_mode=r_ccn, 90 s_geom=sigma_droplet_distribution, 91 ) 92 self.r_wet, self.specific_concentration = spectral_sampling.Logarithmic( 93 spectrum 94 ).sample_deterministic(n_sd) 95 96 self.number_of_ensemble_runs = number_of_ensemble_runs 97 self.dz = dz 98 self.t_max_duration = t_max_duration 99 self.dt = dz / self.w_updraft 100 self.n_output = n_output