Ejemplo n.º 1
0
 def __init__(self, dt=None, grid=None, size=None, dv=None, courant_field_data=None, halo=None):
     self.core = None
     self.dt = dt
     if grid is None:
         self.mesh = Mesh.mesh_0d(dv)
     else:
         if size is None:
             size = tuple(1 for _ in range(len(grid)))
         self.mesh = Mesh(grid, size)
         if halo is not None:
             self.halo = halo
             self.qv = np.empty((grid[0] + 2*halo, grid[1] + 2*halo))
             self.thd = np.empty((grid[0] + 2*halo, grid[1] + 2*halo))
             self.pred = {}
             self.step_counter = 0
     self.courant_field_data = courant_field_data
Ejemplo n.º 2
0
    def test_coalescence_call(n_sd, backend, adaptive):
        # TODO #330
        from PySDM.backends import ThrustRTC
        if backend is ThrustRTC:
            return

        # Arrange
        n = np.ones(n_sd)
        v = np.ones_like(n)
        env = Box(dv=1, dt=default_dt_coal_range[1])
        grid = (25, 25)
        env.mesh = Mesh(grid, size=grid)
        core, sut = get_dummy_core_and_sdm(backend, len(n), environment=env)
        cell_id, _, _ = env.mesh.cellular_attributes(
            Pseudorandom.sample(grid, len(n)))
        attributes = {'n': n, 'volume': v, 'cell id': cell_id}
        core.build(attributes)
        u01, _ = sut.rnd_opt.get_random_arrays()
        sut.actual_length = core.particles._Particles__idx.length
        sut.adaptive = adaptive

        # Act
        sut()

        # Assert
        np.testing.assert_array_equal(
            cell_id, core.particles['cell id'].to_ndarray(raw=True))
Ejemplo n.º 3
0
 def __init__(self, dt, dv, rhod, thd, qv, T, p, RH):
     self.mesh = Mesh.mesh_0d()
     self.full = None
     self.particulator = None
     self.dt = dt
     self.dv = dv
     self.env = {'rhod': rhod, 'thd': thd, 'qv': qv, 'T': T, 'p': p, 'RH': RH}
Ejemplo n.º 4
0
    def __init__(self,
                 dt,
                 mass_of_dry_air: float,
                 p0: float,
                 q0: float,
                 T0: float,
                 w: [float, callable],
                 z0: float = 0):

        super().__init__(dt, Mesh.mesh_0d(), ['rhod', 'z', 't'])

        self.w = w if callable(w) else lambda _: w

        pd0 = p0 * (1 - (1 + const.eps / q0)**-1)
        rhod0 = pd0 / const.Rd / T0

        self.params = (q0, phys.th_std(pd0, T0), rhod0, z0, 0)
        self.mesh.dv = mass_of_dry_air / rhod0

        self.mass_of_dry_air = mass_of_dry_air
Ejemplo n.º 5
0
    def __init__(self,
                 dt,
                 mass_of_dry_air: float,
                 p0: float,
                 q0: float,
                 T0: float,
                 w: [float, callable],
                 z0: float = 0,
                 g=const.g_std):
        super().__init__(dt, Mesh.mesh_0d(), ['rhod', 'z', 't'])

        self.p0 = p0
        self.q0 = q0
        self.T0 = T0
        self.z0 = z0
        self.mass_of_dry_air = mass_of_dry_air
        self.g = g

        self.w = w if callable(w) else lambda _: w

        self.formulae = None
        self.dql = None
Ejemplo n.º 6
0
 def __init__(self, dt, grid, size, rhod_of, field_values):
     super().__init__(dt, Mesh(grid, size), [])
     self.rhod_of = rhod_of
     self.field_values = field_values
Ejemplo n.º 7
0
    def __init__(self, settings, backend=CPU):
        self.nt = settings.nt

        builder = Builder(backend=backend,
                          n_sd=settings.n_sd,
                          formulae=settings.formulae)
        mesh = Mesh(grid=(settings.nz, ), size=(settings.z_max, ))
        env = Kinematic1D(dt=settings.dt,
                          mesh=mesh,
                          thd_of_z=settings.thd,
                          rhod_of_z=settings.rhod)

        mpdata = MPDATA_1D(
            nz=settings.nz,
            dt=settings.dt,
            mpdata_settings=settings.mpdata_settings,
            advector_of_t=lambda t: settings.w(t) * settings.dt / settings.dz,
            advectee_of_zZ_at_t0=lambda zZ: settings.qv(zZ * settings.dz),
            g_factor_of_zZ=lambda zZ: settings.rhod(zZ * settings.dz))

        builder.set_environment(env)
        builder.add_dynamic(AmbientThermodynamics())
        builder.add_dynamic(
            Condensation(adaptive=settings.condensation_adaptive,
                         rtol_thd=settings.condensation_rtol_thd,
                         rtol_x=settings.condensation_rtol_x,
                         kappa=settings.kappa))
        builder.add_dynamic(EulerianAdvection(mpdata))
        if settings.precip:
            builder.add_dynamic(
                Coalescence(kernel=Geometric(collection_efficiency=1),
                            adaptive=settings.coalescence_adaptive))
            builder.add_dynamic(
                Displacement(enable_sedimentation=True,
                             courant_field=(np.zeros(settings.nz +
                                                     1), )))  # TODO #414
        attributes = env.init_attributes(
            spatial_discretisation=spatial_sampling.Pseudorandom(),
            spectral_discretisation=spectral_sampling.ConstantMultiplicity(
                spectrum=settings.wet_radius_spectrum_per_mass_of_dry_air),
            kappa=settings.kappa)
        products = [
            PySDM_products.RelativeHumidity(),
            PySDM_products.Pressure(),
            PySDM_products.Temperature(),
            PySDM_products.WaterVapourMixingRatio(),
            PySDM_products.WaterMixingRatio(
                name='ql',
                description_prefix='cloud',
                radius_range=settings.cloud_water_radius_range),
            PySDM_products.WaterMixingRatio(
                name='qr',
                description_prefix='rain',
                radius_range=settings.rain_water_radius_range),
            PySDM_products.DryAirDensity(),
            PySDM_products.DryAirPotentialTemperature(),
            PySDM_products.ParticlesDrySizeSpectrum(
                v_bins=settings.v_bin_edges),
            PySDM_products.ParticlesWetSizeSpectrum(
                v_bins=settings.v_bin_edges),
            PySDM_products.CloudDropletConcentration(
                radius_range=settings.cloud_water_radius_range),
            PySDM_products.AerosolConcentration(
                radius_threshold=settings.cloud_water_radius_range[0]),
            PySDM_products.ParticleMeanRadius(),
            PySDM_products.RipeningRate(),
            PySDM_products.ActivatingRate(),
            PySDM_products.DeactivatingRate(),
            PySDM_products.CloudDropletEffectiveRadius(
                radius_range=settings.cloud_water_radius_range),
            PySDM_products.PeakSupersaturation()
        ]
        self.core = builder.build(attributes=attributes, products=products)
Ejemplo n.º 8
0
 def __init__(self, dt, dv):
     self.dt = dt
     self.mesh = Mesh.mesh_0d(dv)
     self.core = None
Ejemplo n.º 9
0
 def __init__(self, dt, grid, size, rhod_of):
     super().__init__(dt, Mesh(grid, size), [])
     self.rhod_of = rhod_of
Ejemplo n.º 10
0
 def __init__(self, dt, dv):
     self.dt = dt
     self.mesh = Mesh.mesh_0d(dv)
     self.particulator = None
     self._ambient_air = {}