PySDM_examples.Bulenok_2023_MasterThesis.setups
1from PySDM_examples.Bulenok_2023_MasterThesis.utils import ProductsNames 2from PySDM_examples.Srivastava_1982 import Settings 3from PySDM_examples.Srivastava_1982.simulation import Simulation 4 5from PySDM.dynamics import Collision 6from PySDM.dynamics.collisions.breakup_efficiencies import ConstEb 7from PySDM.dynamics.collisions.breakup_fragmentations import ConstantMass 8from PySDM.dynamics.collisions.coalescence_efficiencies import ConstEc 9from PySDM.dynamics.collisions.collision_kernels import ConstantK 10from PySDM.physics import si 11from PySDM.products import SuperDropletCountPerGridbox, VolumeFirstMoment, ZerothMoment 12 13dt = 1 * si.s 14DV = 1 * si.m**3 15drop_mass_0 = 1 * si.g 16 17TOTAL_NUMBER = 1e12 18 19NO_BOUNCE = ConstEb(1) 20 21 22def make_settings(n_sd, total_number, dv, c, beta, frag_mass, backend_class): 23 if total_number is None: 24 total_number = TOTAL_NUMBER 25 elif callable(total_number): 26 total_number = total_number(n_sd) 27 28 if dv is None: 29 dv = DV 30 elif callable(dv): 31 dv = dv(n_sd) 32 33 print() 34 print("== Settings ==") 35 print("n_sd", n_sd) 36 print("total_number", total_number) 37 print("dv", dv) 38 print() 39 40 return Settings( 41 srivastava_c=c, 42 srivastava_beta=beta, 43 frag_mass=frag_mass, 44 drop_mass_0=drop_mass_0, 45 dt=dt, 46 dv=dv, 47 n_sds=(), 48 total_number=total_number, 49 backend_class=backend_class, 50 ) 51 52 53def setup_simulation(settings, n_sd, seed, double_precision=True): 54 products = ( 55 SuperDropletCountPerGridbox(name=ProductsNames.super_particle_count), 56 VolumeFirstMoment(name=ProductsNames.total_volume), 57 ZerothMoment(name=ProductsNames.total_number), 58 ) 59 60 collision_rate = settings.srivastava_c + settings.srivastava_beta 61 simulation = Simulation( 62 n_steps=None, 63 settings=settings, 64 collision_dynamic=Collision( 65 collision_kernel=ConstantK(a=collision_rate), 66 coalescence_efficiency=ConstEc(settings.srivastava_c / collision_rate), 67 breakup_efficiency=NO_BOUNCE, 68 fragmentation_function=ConstantMass(c=settings.frag_mass / settings.rho), 69 warn_overflows=False, 70 adaptive=False, 71 ), 72 double_precision=double_precision, 73 ) 74 particulator = simulation.build(n_sd, seed, products=products) 75 76 return particulator 77 78 79def setup_coalescence_only_sim( 80 n_sd, backend_class, seed, double_precision=True, total_number=None, dv=None 81): 82 c = 0.5e-6 / si.s 83 beta = 1e-15 / si.s 84 frag_mass = -1 * si.g 85 86 settings = make_settings(n_sd, total_number, dv, c, beta, frag_mass, backend_class) 87 88 return setup_simulation(settings, n_sd, seed, double_precision) 89 90 91def setup_breakup_only_sim( 92 n_sd, backend_class, seed, double_precision=True, total_number=None, dv=None 93): 94 c = 1e-15 / si.s 95 beta = 1e-9 / si.s 96 frag_mass = 0.25 * si.g 97 98 settings = make_settings(n_sd, total_number, dv, c, beta, frag_mass, backend_class) 99 100 return setup_simulation(settings, n_sd, seed, double_precision) 101 102 103def setup_coalescence_breakup_sim( 104 n_sd, backend_class, seed, double_precision=True, total_number=None, dv=None 105): 106 c = 0.5e-6 / si.s 107 beta = 1e-9 / si.s 108 frag_mass = 0.25 * si.g 109 110 settings = make_settings(n_sd, total_number, dv, c, beta, frag_mass, backend_class) 111 112 return setup_simulation(settings, n_sd, seed, double_precision)
dt =
1.0
DV =
1.0
drop_mass_0 =
0.001
TOTAL_NUMBER =
1000000000000.0
NO_BOUNCE =
<PySDM.dynamics.collisions.breakup_efficiencies.constEb.ConstEb object>
def
make_settings(n_sd, total_number, dv, c, beta, frag_mass, backend_class):
23def make_settings(n_sd, total_number, dv, c, beta, frag_mass, backend_class): 24 if total_number is None: 25 total_number = TOTAL_NUMBER 26 elif callable(total_number): 27 total_number = total_number(n_sd) 28 29 if dv is None: 30 dv = DV 31 elif callable(dv): 32 dv = dv(n_sd) 33 34 print() 35 print("== Settings ==") 36 print("n_sd", n_sd) 37 print("total_number", total_number) 38 print("dv", dv) 39 print() 40 41 return Settings( 42 srivastava_c=c, 43 srivastava_beta=beta, 44 frag_mass=frag_mass, 45 drop_mass_0=drop_mass_0, 46 dt=dt, 47 dv=dv, 48 n_sds=(), 49 total_number=total_number, 50 backend_class=backend_class, 51 )
def
setup_simulation(settings, n_sd, seed, double_precision=True):
54def setup_simulation(settings, n_sd, seed, double_precision=True): 55 products = ( 56 SuperDropletCountPerGridbox(name=ProductsNames.super_particle_count), 57 VolumeFirstMoment(name=ProductsNames.total_volume), 58 ZerothMoment(name=ProductsNames.total_number), 59 ) 60 61 collision_rate = settings.srivastava_c + settings.srivastava_beta 62 simulation = Simulation( 63 n_steps=None, 64 settings=settings, 65 collision_dynamic=Collision( 66 collision_kernel=ConstantK(a=collision_rate), 67 coalescence_efficiency=ConstEc(settings.srivastava_c / collision_rate), 68 breakup_efficiency=NO_BOUNCE, 69 fragmentation_function=ConstantMass(c=settings.frag_mass / settings.rho), 70 warn_overflows=False, 71 adaptive=False, 72 ), 73 double_precision=double_precision, 74 ) 75 particulator = simulation.build(n_sd, seed, products=products) 76 77 return particulator
def
setup_coalescence_only_sim( n_sd, backend_class, seed, double_precision=True, total_number=None, dv=None):
80def setup_coalescence_only_sim( 81 n_sd, backend_class, seed, double_precision=True, total_number=None, dv=None 82): 83 c = 0.5e-6 / si.s 84 beta = 1e-15 / si.s 85 frag_mass = -1 * si.g 86 87 settings = make_settings(n_sd, total_number, dv, c, beta, frag_mass, backend_class) 88 89 return setup_simulation(settings, n_sd, seed, double_precision)
def
setup_breakup_only_sim( n_sd, backend_class, seed, double_precision=True, total_number=None, dv=None):
92def setup_breakup_only_sim( 93 n_sd, backend_class, seed, double_precision=True, total_number=None, dv=None 94): 95 c = 1e-15 / si.s 96 beta = 1e-9 / si.s 97 frag_mass = 0.25 * si.g 98 99 settings = make_settings(n_sd, total_number, dv, c, beta, frag_mass, backend_class) 100 101 return setup_simulation(settings, n_sd, seed, double_precision)
def
setup_coalescence_breakup_sim( n_sd, backend_class, seed, double_precision=True, total_number=None, dv=None):
104def setup_coalescence_breakup_sim( 105 n_sd, backend_class, seed, double_precision=True, total_number=None, dv=None 106): 107 c = 0.5e-6 / si.s 108 beta = 1e-9 / si.s 109 frag_mass = 0.25 * si.g 110 111 settings = make_settings(n_sd, total_number, dv, c, beta, frag_mass, backend_class) 112 113 return setup_simulation(settings, n_sd, seed, double_precision)