PySDM_examples.Shima_et_al_2009.tutorial_example

 1from PySDM.backends import CPU
 2from PySDM.builder import Builder
 3from PySDM.dynamics import Coalescence
 4from PySDM.environments import Box
 5from PySDM.initialisation.sampling.spectral_sampling import ConstantMultiplicity
 6from PySDM.products import ParticleVolumeVersusRadiusLogarithmSpectrum, WallTime
 7
 8
 9def run(settings, observers=()):
10    builder = Builder(n_sd=settings.n_sd, backend=CPU(formulae=settings.formulae))
11    builder.set_environment(Box(dv=settings.dv, dt=settings.dt))
12    attributes = {}
13    sampling = ConstantMultiplicity(settings.spectrum)
14    attributes["volume"], attributes["n"] = sampling.sample(settings.n_sd)
15    coalescence = Coalescence(
16        collision_kernel=settings.kernel, adaptive=settings.adaptive
17    )
18    builder.add_dynamic(coalescence)
19    products = (
20        ParticleVolumeVersusRadiusLogarithmSpectrum(
21            settings.radius_bins_edges, name="dv/dlnr"
22        ),
23        WallTime(),
24    )
25    particulator = builder.build(attributes, products)
26    if hasattr(settings, "u_term") and "terminal velocity" in particulator.attributes:
27        particulator.attributes["terminal velocity"].approximation = settings.u_term(
28            particulator
29        )
30
31    for observer in observers:
32        particulator.observers.append(observer)
33
34    vals = {}
35    particulator.products["wall time"].reset()
36    for step in settings.output_steps:
37        particulator.run(step - particulator.n_steps)
38        vals[step] = particulator.products["dv/dlnr"].get()[0]
39        vals[step][:] *= settings.rho
40
41    exec_time = particulator.products["wall time"].get()
42    return vals, exec_time
def run(settings, observers=()):
10def run(settings, observers=()):
11    builder = Builder(n_sd=settings.n_sd, backend=CPU(formulae=settings.formulae))
12    builder.set_environment(Box(dv=settings.dv, dt=settings.dt))
13    attributes = {}
14    sampling = ConstantMultiplicity(settings.spectrum)
15    attributes["volume"], attributes["n"] = sampling.sample(settings.n_sd)
16    coalescence = Coalescence(
17        collision_kernel=settings.kernel, adaptive=settings.adaptive
18    )
19    builder.add_dynamic(coalescence)
20    products = (
21        ParticleVolumeVersusRadiusLogarithmSpectrum(
22            settings.radius_bins_edges, name="dv/dlnr"
23        ),
24        WallTime(),
25    )
26    particulator = builder.build(attributes, products)
27    if hasattr(settings, "u_term") and "terminal velocity" in particulator.attributes:
28        particulator.attributes["terminal velocity"].approximation = settings.u_term(
29            particulator
30        )
31
32    for observer in observers:
33        particulator.observers.append(observer)
34
35    vals = {}
36    particulator.products["wall time"].reset()
37    for step in settings.output_steps:
38        particulator.run(step - particulator.n_steps)
39        vals[step] = particulator.products["dv/dlnr"].get()[0]
40        vals[step][:] *= settings.rho
41
42    exec_time = particulator.products["wall time"].get()
43    return vals, exec_time