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

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

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

    exec_time = core.products['wall_time'].get()
    return vals, exec_time
예제 #2
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