PySDM_examples.deJong_Mackay_et_al_2023.simulation1D

 1import numpy as np
 2from PySDM_examples.Shipway_and_Hill_2012.simulation import Simulation as SimulationSH
 3
 4import PySDM.products as PySDM_products
 5from PySDM.dynamics import Collision
 6from PySDM.dynamics.collisions.collision_kernels import Geometric
 7from PySDM.physics import si
 8
 9
10class Simulation1D(SimulationSH):
11    def __init__(self, settings):
12        super().__init__(settings)
13        self.output_steps = settings.output_steps
14
15    @staticmethod
16    def add_collision_dynamic(builder, settings, products):
17        if settings.breakup:
18            builder.add_dynamic(
19                Collision(
20                    collision_kernel=Geometric(collection_efficiency=1),
21                    coalescence_efficiency=settings.coalescence_efficiency,
22                    breakup_efficiency=settings.breakup_efficiency,
23                    fragmentation_function=settings.fragmentation_function,
24                    adaptive=settings.coalescence_adaptive,
25                    warn_overflows=settings.warn_breakup_overflow,
26                )
27            )
28            products.append(
29                PySDM_products.BreakupRateDeficitPerGridbox(
30                    name="breakup_deficit",
31                )
32            )
33            products.append(
34                PySDM_products.BreakupRatePerGridbox(
35                    name="breakup_rate",
36                )
37            )
38        else:
39            SimulationSH.add_collision_dynamic(builder, settings, products)
40
41        radius_bins_edges = np.logspace(
42            np.log10(0.01 * si.um), np.log10(5000 * si.um), num=101, endpoint=True
43        )
44        products.append(
45            PySDM_products.NumberSizeSpectrum(
46                name="N(v)", radius_bins_edges=radius_bins_edges
47            )
48        )
49        products.append(
50            PySDM_products.ParticleVolumeVersusRadiusLogarithmSpectrum(
51                name="dvdlnr", radius_bins_edges=radius_bins_edges
52            )
53        )
54
55    def save(self, step):
56        if step in self.output_steps:
57            super().save(step)
58
59    def run(self):
60        result = super().run()
61        for key, val in result.products.items():
62            if len(val.shape) == 2:
63                result.products[key] = val[:, self.output_steps]
64            elif len(val.shape) == 3:
65                result.products[key] = val[:, :, :]
66        result.products["t"] = result.products["t"][self.output_steps]
67        return result
11class Simulation1D(SimulationSH):
12    def __init__(self, settings):
13        super().__init__(settings)
14        self.output_steps = settings.output_steps
15
16    @staticmethod
17    def add_collision_dynamic(builder, settings, products):
18        if settings.breakup:
19            builder.add_dynamic(
20                Collision(
21                    collision_kernel=Geometric(collection_efficiency=1),
22                    coalescence_efficiency=settings.coalescence_efficiency,
23                    breakup_efficiency=settings.breakup_efficiency,
24                    fragmentation_function=settings.fragmentation_function,
25                    adaptive=settings.coalescence_adaptive,
26                    warn_overflows=settings.warn_breakup_overflow,
27                )
28            )
29            products.append(
30                PySDM_products.BreakupRateDeficitPerGridbox(
31                    name="breakup_deficit",
32                )
33            )
34            products.append(
35                PySDM_products.BreakupRatePerGridbox(
36                    name="breakup_rate",
37                )
38            )
39        else:
40            SimulationSH.add_collision_dynamic(builder, settings, products)
41
42        radius_bins_edges = np.logspace(
43            np.log10(0.01 * si.um), np.log10(5000 * si.um), num=101, endpoint=True
44        )
45        products.append(
46            PySDM_products.NumberSizeSpectrum(
47                name="N(v)", radius_bins_edges=radius_bins_edges
48            )
49        )
50        products.append(
51            PySDM_products.ParticleVolumeVersusRadiusLogarithmSpectrum(
52                name="dvdlnr", radius_bins_edges=radius_bins_edges
53            )
54        )
55
56    def save(self, step):
57        if step in self.output_steps:
58            super().save(step)
59
60    def run(self):
61        result = super().run()
62        for key, val in result.products.items():
63            if len(val.shape) == 2:
64                result.products[key] = val[:, self.output_steps]
65            elif len(val.shape) == 3:
66                result.products[key] = val[:, :, :]
67        result.products["t"] = result.products["t"][self.output_steps]
68        return result
Simulation1D(settings)
12    def __init__(self, settings):
13        super().__init__(settings)
14        self.output_steps = settings.output_steps
output_steps
@staticmethod
def add_collision_dynamic(builder, settings, products):
16    @staticmethod
17    def add_collision_dynamic(builder, settings, products):
18        if settings.breakup:
19            builder.add_dynamic(
20                Collision(
21                    collision_kernel=Geometric(collection_efficiency=1),
22                    coalescence_efficiency=settings.coalescence_efficiency,
23                    breakup_efficiency=settings.breakup_efficiency,
24                    fragmentation_function=settings.fragmentation_function,
25                    adaptive=settings.coalescence_adaptive,
26                    warn_overflows=settings.warn_breakup_overflow,
27                )
28            )
29            products.append(
30                PySDM_products.BreakupRateDeficitPerGridbox(
31                    name="breakup_deficit",
32                )
33            )
34            products.append(
35                PySDM_products.BreakupRatePerGridbox(
36                    name="breakup_rate",
37                )
38            )
39        else:
40            SimulationSH.add_collision_dynamic(builder, settings, products)
41
42        radius_bins_edges = np.logspace(
43            np.log10(0.01 * si.um), np.log10(5000 * si.um), num=101, endpoint=True
44        )
45        products.append(
46            PySDM_products.NumberSizeSpectrum(
47                name="N(v)", radius_bins_edges=radius_bins_edges
48            )
49        )
50        products.append(
51            PySDM_products.ParticleVolumeVersusRadiusLogarithmSpectrum(
52                name="dvdlnr", radius_bins_edges=radius_bins_edges
53            )
54        )
def save(self, step):
56    def save(self, step):
57        if step in self.output_steps:
58            super().save(step)
def run(self):
60    def run(self):
61        result = super().run()
62        for key, val in result.products.items():
63            if len(val.shape) == 2:
64                result.products[key] = val[:, self.output_steps]
65            elif len(val.shape) == 3:
66                result.products[key] = val[:, :, :]
67        result.products["t"] = result.products["t"][self.output_steps]
68        return result