예제 #1
0
def run(setup, observers=()):
    builder = Builder(n_sd=setup.n_sd, backend=setup.backend)
    builder.set_environment(Box(dv=setup.dv, dt=setup.dt))
    attributes = {}
    attributes['volume'], attributes['n'] = constant_multiplicity(
        setup.n_sd, setup.spectrum, (setup.init_x_min, setup.init_x_max))
    coalescence = Coalescence(setup.kernel)
    coalescence.adaptive = setup.adaptive
    builder.add_dynamic(coalescence)
    products = [ParticlesVolumeSpectrum()]
    particles = builder.build(attributes, products)
    if hasattr(setup,
               'u_term') and 'terminal velocity' in particles.state.attributes:
        particles.state.attributes[
            'terminal velocity'].approximation = setup.u_term(particles)

    for observer in observers:
        particles.observers.append(observer)

    vals = {}
    for step in setup.steps:
        particles.run(step - particles.n_steps)
        vals[step] = particles.products['dv/dlnr'].get(setup.radius_bins_edges)
        vals[step][:] *= setup.rho

    return vals, particles.stats
예제 #2
0
def run(setup):
    builder = Builder(n_sd=setup.n_sd, backend=setup.backend)
    builder.set_environment(Box(dv=setup.dv, dt=setup.dt))
    v, n = constant_multiplicity(setup.n_sd, setup.spectrum,
                                 (setup.init_x_min, setup.init_x_max))
    attributes = {'n': n, 'volume': v}
    builder.add_dynamic(Coalescence(setup.kernel))

    particles = builder.build(attributes)

    states = {}
    for step in setup.steps:
        particles.run(step - particles.n_steps)

    return states, particles.stats
예제 #3
0
def run(setup):
    particles_building = ParticlesBuilder(n_sd=setup.n_sd,
                                          backend=setup.backend)
    particles_building.set_environment(Box, {'dv': setup.dv, 'dt': setup.dt})
    v, n = constant_multiplicity(setup.n_sd, setup.spectrum,
                                 (setup.init_x_min, setup.init_x_max))
    attributes = {'n': n, 'volume': v}
    particles_building.register_dynamic(Coalescence, {"kernel": setup.kernel})

    particles = particles_building.get_particles(attributes)

    states = {}
    for step in setup.steps:
        particles.run(step - particles.n_steps)

    return states, particles.stats
예제 #4
0
def run(setup):
    particles_builder = ParticlesBuilder(n_sd=setup.n_sd, backend=setup.backend)
    particles_builder.set_environment(Box, {"dv": setup.dv, "dt": setup.dt})
    attributes = {}
    attributes['volume'], attributes['n'] = constant_multiplicity(setup.n_sd, setup.spectrum,
                                                                  (setup.init_x_min, setup.init_x_max))
    particles_builder.register_dynamic(Coalescence, {"kernel": setup.kernel})
    products = {ParticlesVolumeSpectrum: {}}
    particles = particles_builder.get_particles(attributes, products)

    vals = {}
    for step in setup.steps:
        particles.run(step - particles.n_steps)
        vals[step] = particles.products['dv/dlnr'].get(setup.radius_bins_edges)
        vals[step][:] *= setup.rho

    return vals, particles.stats
예제 #5
0
def test_coalescence(croupier):
    # Arrange
    v_min = 4.186e-15
    v_max = 4.186e-12
    n_sd = 2**13
    steps = [0, 30, 60]
    X0 = 4 / 3 * np.pi * 30.531e-6**3
    n_part = 2**23 / si.metre**3
    dv = 1e6 * si.metres**3
    dt = 1 * si.seconds
    norm_factor = n_part * dv
    rho = 1000 * si.kilogram / si.metre**3

    kernel = Golovin(b=1.5e3)  # [s-1]
    spectrum = Exponential(norm_factor=norm_factor, scale=X0)
    particles_builder = Builder(n_sd=n_sd, backend=backend)
    particles_builder.set_environment(Box(dt=dt, dv=dv))
    attributes = {}
    attributes['volume'], attributes['n'] = constant_multiplicity(
        n_sd, spectrum, (v_min, v_max))
    particles_builder.add_dynamic(Coalescence(kernel, seed=256))
    particles = particles_builder.build(attributes)
    particles.croupier = croupier

    class Seed:
        seed = 0

        def __call__(self):
            Seed.seed += 1
            return Seed.seed

    particles.dynamics[str(Coalescence)].seed = Seed()

    states = {}

    # Act
    for step in steps:
        particles.run(step - particles.n_steps)
        check(n_part, dv, n_sd, rho, particles.state, step)
        states[particles.n_steps] = copy.deepcopy(particles.state)

    # Assert
    x_max = 0
    for state in states.values():
        assert x_max < np.amax(state['volume'].to_ndarray())
        x_max = np.amax(state['volume'].to_ndarray())