PySDM_examples.Kreidenweis_et_al_2003.simulation
1import numpy as np 2from PySDM_examples.utils import BasicSimulation 3 4import PySDM.products as PySDM_products 5from PySDM import Builder 6from PySDM.backends import CPU 7from PySDM.dynamics import AmbientThermodynamics, AqueousChemistry, Condensation 8from PySDM.dynamics.impl.chemistry_utils import AQUEOUS_COMPOUNDS, GASEOUS_COMPOUNDS 9from PySDM.environments import Parcel 10from PySDM.physics import si 11 12 13class Simulation(BasicSimulation): 14 def __init__(self, settings, products=None): 15 builder = Builder( 16 n_sd=settings.n_sd, 17 backend=CPU( 18 formulae=settings.formulae, override_jit_flags={"parallel": False} 19 ), 20 environment=Parcel( 21 dt=settings.dt, 22 mass_of_dry_air=settings.mass_of_dry_air, 23 p0=settings.p0, 24 initial_water_vapour_mixing_ratio=settings.initial_water_vapour_mixing_ratio, 25 T0=settings.T0, 26 w=settings.w, 27 ), 28 ) 29 30 attributes = builder.particulator.environment.init_attributes( 31 n_in_dv=settings.n_in_dv, 32 kappa=settings.kappa, 33 r_dry=settings.r_dry, 34 include_dry_volume_in_attribute=False, 35 ) 36 attributes = { 37 **attributes, 38 **settings.starting_amounts, 39 } 40 41 builder.add_dynamic(AmbientThermodynamics()) 42 builder.add_dynamic(Condensation()) 43 builder.add_dynamic( 44 AqueousChemistry( 45 environment_mole_fractions=settings.ENVIRONMENT_MOLE_FRACTIONS, 46 system_type=settings.system_type, 47 n_substep=settings.n_substep, 48 dry_rho=settings.DRY_RHO, 49 dry_molar_mass=settings.dry_molar_mass, 50 ) 51 ) 52 53 products = products or ( 54 PySDM_products.AmbientRelativeHumidity(name="RH", unit="%"), 55 PySDM_products.WaterMixingRatio( 56 name="liquid water mixing ratio", 57 radius_range=[1 * si.um, np.inf], 58 unit="g/kg", 59 ), 60 PySDM_products.ParcelDisplacement(name="z"), 61 PySDM_products.AmbientPressure(name="p"), 62 PySDM_products.AmbientTemperature(name="T"), 63 PySDM_products.AmbientDryAirDensity(name="rhod"), 64 PySDM_products.AmbientWaterVapourMixingRatio( 65 name="water vapour mixing ratio", 66 var="water_vapour_mixing_ratio", 67 unit="g/kg", 68 ), 69 PySDM_products.Time(name="t"), 70 *( 71 PySDM_products.AqueousMoleFraction( 72 comp, unit="ppb", name=f"aq_{comp}_ppb" 73 ) 74 for comp in AQUEOUS_COMPOUNDS 75 ), 76 *( 77 PySDM_products.GaseousMoleFraction( 78 comp, unit="ppb", name=f"gas_{comp}_ppb" 79 ) 80 for comp in GASEOUS_COMPOUNDS 81 ), 82 PySDM_products.Acidity( 83 name="pH_pH_number_weighted", 84 radius_range=settings.cloud_radius_range, 85 weighting="number", 86 attr="pH", 87 ), 88 PySDM_products.Acidity( 89 name="pH_pH_volume_weighted", 90 radius_range=settings.cloud_radius_range, 91 weighting="volume", 92 attr="pH", 93 ), 94 PySDM_products.Acidity( 95 name="pH_conc_H_number_weighted", 96 radius_range=settings.cloud_radius_range, 97 weighting="number", 98 attr="conc_H", 99 ), 100 PySDM_products.Acidity( 101 name="pH_conc_H_volume_weighted", 102 radius_range=settings.cloud_radius_range, 103 weighting="volume", 104 attr="conc_H", 105 ), 106 PySDM_products.TotalDryMassMixingRatio( 107 settings.DRY_RHO, name="q_dry", unit="ug/kg" 108 ), 109 PySDM_products.PeakSupersaturation(unit="%", name="S_max"), 110 PySDM_products.ParticleSpecificConcentration( 111 radius_range=settings.cloud_radius_range, name="n_c_mg", unit="mg^-1" 112 ), 113 PySDM_products.AqueousMassSpectrum( 114 key="S_VI", 115 dry_radius_bins_edges=settings.dry_radius_bins_edges, 116 name="dm_S_VI/dlog_10(dry diameter)", 117 unit="ug / m^3", 118 ), 119 ) 120 121 particulator = builder.build(attributes=attributes, products=products) 122 self.settings = settings 123 super().__init__(particulator=particulator) 124 125 def run(self): 126 return super()._run(self.settings.nt, self.settings.steps_per_output_interval)
14class Simulation(BasicSimulation): 15 def __init__(self, settings, products=None): 16 builder = Builder( 17 n_sd=settings.n_sd, 18 backend=CPU( 19 formulae=settings.formulae, override_jit_flags={"parallel": False} 20 ), 21 environment=Parcel( 22 dt=settings.dt, 23 mass_of_dry_air=settings.mass_of_dry_air, 24 p0=settings.p0, 25 initial_water_vapour_mixing_ratio=settings.initial_water_vapour_mixing_ratio, 26 T0=settings.T0, 27 w=settings.w, 28 ), 29 ) 30 31 attributes = builder.particulator.environment.init_attributes( 32 n_in_dv=settings.n_in_dv, 33 kappa=settings.kappa, 34 r_dry=settings.r_dry, 35 include_dry_volume_in_attribute=False, 36 ) 37 attributes = { 38 **attributes, 39 **settings.starting_amounts, 40 } 41 42 builder.add_dynamic(AmbientThermodynamics()) 43 builder.add_dynamic(Condensation()) 44 builder.add_dynamic( 45 AqueousChemistry( 46 environment_mole_fractions=settings.ENVIRONMENT_MOLE_FRACTIONS, 47 system_type=settings.system_type, 48 n_substep=settings.n_substep, 49 dry_rho=settings.DRY_RHO, 50 dry_molar_mass=settings.dry_molar_mass, 51 ) 52 ) 53 54 products = products or ( 55 PySDM_products.AmbientRelativeHumidity(name="RH", unit="%"), 56 PySDM_products.WaterMixingRatio( 57 name="liquid water mixing ratio", 58 radius_range=[1 * si.um, np.inf], 59 unit="g/kg", 60 ), 61 PySDM_products.ParcelDisplacement(name="z"), 62 PySDM_products.AmbientPressure(name="p"), 63 PySDM_products.AmbientTemperature(name="T"), 64 PySDM_products.AmbientDryAirDensity(name="rhod"), 65 PySDM_products.AmbientWaterVapourMixingRatio( 66 name="water vapour mixing ratio", 67 var="water_vapour_mixing_ratio", 68 unit="g/kg", 69 ), 70 PySDM_products.Time(name="t"), 71 *( 72 PySDM_products.AqueousMoleFraction( 73 comp, unit="ppb", name=f"aq_{comp}_ppb" 74 ) 75 for comp in AQUEOUS_COMPOUNDS 76 ), 77 *( 78 PySDM_products.GaseousMoleFraction( 79 comp, unit="ppb", name=f"gas_{comp}_ppb" 80 ) 81 for comp in GASEOUS_COMPOUNDS 82 ), 83 PySDM_products.Acidity( 84 name="pH_pH_number_weighted", 85 radius_range=settings.cloud_radius_range, 86 weighting="number", 87 attr="pH", 88 ), 89 PySDM_products.Acidity( 90 name="pH_pH_volume_weighted", 91 radius_range=settings.cloud_radius_range, 92 weighting="volume", 93 attr="pH", 94 ), 95 PySDM_products.Acidity( 96 name="pH_conc_H_number_weighted", 97 radius_range=settings.cloud_radius_range, 98 weighting="number", 99 attr="conc_H", 100 ), 101 PySDM_products.Acidity( 102 name="pH_conc_H_volume_weighted", 103 radius_range=settings.cloud_radius_range, 104 weighting="volume", 105 attr="conc_H", 106 ), 107 PySDM_products.TotalDryMassMixingRatio( 108 settings.DRY_RHO, name="q_dry", unit="ug/kg" 109 ), 110 PySDM_products.PeakSupersaturation(unit="%", name="S_max"), 111 PySDM_products.ParticleSpecificConcentration( 112 radius_range=settings.cloud_radius_range, name="n_c_mg", unit="mg^-1" 113 ), 114 PySDM_products.AqueousMassSpectrum( 115 key="S_VI", 116 dry_radius_bins_edges=settings.dry_radius_bins_edges, 117 name="dm_S_VI/dlog_10(dry diameter)", 118 unit="ug / m^3", 119 ), 120 ) 121 122 particulator = builder.build(attributes=attributes, products=products) 123 self.settings = settings 124 super().__init__(particulator=particulator) 125 126 def run(self): 127 return super()._run(self.settings.nt, self.settings.steps_per_output_interval)
Simulation(settings, products=None)
15 def __init__(self, settings, products=None): 16 builder = Builder( 17 n_sd=settings.n_sd, 18 backend=CPU( 19 formulae=settings.formulae, override_jit_flags={"parallel": False} 20 ), 21 environment=Parcel( 22 dt=settings.dt, 23 mass_of_dry_air=settings.mass_of_dry_air, 24 p0=settings.p0, 25 initial_water_vapour_mixing_ratio=settings.initial_water_vapour_mixing_ratio, 26 T0=settings.T0, 27 w=settings.w, 28 ), 29 ) 30 31 attributes = builder.particulator.environment.init_attributes( 32 n_in_dv=settings.n_in_dv, 33 kappa=settings.kappa, 34 r_dry=settings.r_dry, 35 include_dry_volume_in_attribute=False, 36 ) 37 attributes = { 38 **attributes, 39 **settings.starting_amounts, 40 } 41 42 builder.add_dynamic(AmbientThermodynamics()) 43 builder.add_dynamic(Condensation()) 44 builder.add_dynamic( 45 AqueousChemistry( 46 environment_mole_fractions=settings.ENVIRONMENT_MOLE_FRACTIONS, 47 system_type=settings.system_type, 48 n_substep=settings.n_substep, 49 dry_rho=settings.DRY_RHO, 50 dry_molar_mass=settings.dry_molar_mass, 51 ) 52 ) 53 54 products = products or ( 55 PySDM_products.AmbientRelativeHumidity(name="RH", unit="%"), 56 PySDM_products.WaterMixingRatio( 57 name="liquid water mixing ratio", 58 radius_range=[1 * si.um, np.inf], 59 unit="g/kg", 60 ), 61 PySDM_products.ParcelDisplacement(name="z"), 62 PySDM_products.AmbientPressure(name="p"), 63 PySDM_products.AmbientTemperature(name="T"), 64 PySDM_products.AmbientDryAirDensity(name="rhod"), 65 PySDM_products.AmbientWaterVapourMixingRatio( 66 name="water vapour mixing ratio", 67 var="water_vapour_mixing_ratio", 68 unit="g/kg", 69 ), 70 PySDM_products.Time(name="t"), 71 *( 72 PySDM_products.AqueousMoleFraction( 73 comp, unit="ppb", name=f"aq_{comp}_ppb" 74 ) 75 for comp in AQUEOUS_COMPOUNDS 76 ), 77 *( 78 PySDM_products.GaseousMoleFraction( 79 comp, unit="ppb", name=f"gas_{comp}_ppb" 80 ) 81 for comp in GASEOUS_COMPOUNDS 82 ), 83 PySDM_products.Acidity( 84 name="pH_pH_number_weighted", 85 radius_range=settings.cloud_radius_range, 86 weighting="number", 87 attr="pH", 88 ), 89 PySDM_products.Acidity( 90 name="pH_pH_volume_weighted", 91 radius_range=settings.cloud_radius_range, 92 weighting="volume", 93 attr="pH", 94 ), 95 PySDM_products.Acidity( 96 name="pH_conc_H_number_weighted", 97 radius_range=settings.cloud_radius_range, 98 weighting="number", 99 attr="conc_H", 100 ), 101 PySDM_products.Acidity( 102 name="pH_conc_H_volume_weighted", 103 radius_range=settings.cloud_radius_range, 104 weighting="volume", 105 attr="conc_H", 106 ), 107 PySDM_products.TotalDryMassMixingRatio( 108 settings.DRY_RHO, name="q_dry", unit="ug/kg" 109 ), 110 PySDM_products.PeakSupersaturation(unit="%", name="S_max"), 111 PySDM_products.ParticleSpecificConcentration( 112 radius_range=settings.cloud_radius_range, name="n_c_mg", unit="mg^-1" 113 ), 114 PySDM_products.AqueousMassSpectrum( 115 key="S_VI", 116 dry_radius_bins_edges=settings.dry_radius_bins_edges, 117 name="dm_S_VI/dlog_10(dry diameter)", 118 unit="ug / m^3", 119 ), 120 ) 121 122 particulator = builder.build(attributes=attributes, products=products) 123 self.settings = settings 124 super().__init__(particulator=particulator)