コード例 #1
0
ファイル: dla2d_tests.py プロジェクト: sjrowlinson/droplet
def real_time_test(nparticles, lattice_type, stickiness=1.0, save=False, blitting=True,
                   filename=None):
    """Generates an aggregate of `nparticles` in real-time on a specified lattice
    with a single point attractor as the initial seed.

    Parameters:
    -----------
    nparticles -- Number of particles to generate.
    lattice_type -- Type of lattice.
    stickiness -- Stickiness value of the aggregate [default 1.0].
    save -- Determines whether to save the simulation to a file with
    name and extension specified by `filename`.
    blitting -- Determines whether to perform blitting for improved real-time
    rendering performance.
    filename -- Name and extension of file if saving the simulation.

    Returns:
    --------
    The handle to the simulation instance.
    """
    point_agg_rt = drp.Aggregate2D(stickiness=stickiness,
                                   lattice_type=lattice_type)
    sim = RealTimeAggregate2D(point_agg_rt, nparticles, save=save, blitting=blitting,
                              filename=filename)
    return sim
コード例 #2
0
def boundary_collisions_test(nparticles):
    aggregate = drp.Aggregate2D()
    aggregate.generate(nparticles)
    fig, axes = plt.subplots()
    prange = np.arange(nparticles)
    axes.plot(prange, aggregate.boundary_collisions)
    axes.set_xlabel('Aggregate Particle Index')
    axes.set_ylabel('Boundary Collsions')
    fig.show()
コード例 #3
0
def steps_to_stick_test(nparticles):
    aggregate = drp.Aggregate2D()
    aggregate.generate(nparticles)
    fig, axes = plt.subplots()
    prange = np.arange(nparticles)
    axes.plot(prange, aggregate.required_steps)
    axes.set_xlabel('Aggregate Particle Index')
    axes.set_ylabel('Lattice Steps to Stick')
    fig.show()
コード例 #4
0
def combined_test(nparticles,
                  scalefactor=3.0,
                  save=False,
                  filename=None,
                  plot_sma=True,
                  sma_period=None):
    aggregate = drp.Aggregate2D(lattice_type=drp.LatticeType.TRIANGLE)
    aggregate.generate(nparticles)
    prange = np.arange(nparticles)
    fig = plt.figure(figsize=(14, 7))
    figdims = [(2, 2, 1), (2, 2, 3), (2, 2, (2, 4))]
    for row, col, plotno in figdims:
        sub = fig.add_subplot(row, col, plotno)
        if plotno == 1:
            sub.plot(prange,
                     aggregate.required_steps,
                     'b',
                     label=r"Required steps")
            if plot_sma:
                rqd_steps_ma = simple_moving_average(aggregate.required_steps,
                                                     sma_period)
                sub.plot(rqd_steps_ma[:, 0],
                         rqd_steps_ma[:, 1],
                         'r',
                         label=r"{} particle SMA".format(sma_period))
            sub.set_xlabel('Aggregate Particle Index')
            sub.set_ylabel('Lattice Steps to Stick')
            sub.legend()
        elif plotno == 3:
            sub.plot(prange,
                     aggregate.boundary_collisions,
                     'g',
                     label=r"Boundary collisions")
            if plot_sma:
                bcoll_ma = simple_moving_average(aggregate.boundary_collisions,
                                                 sma_period)
                sub.plot(bcoll_ma[:, 0],
                         bcoll_ma[:, 1],
                         'r',
                         label=r"{} particle SMA".format(sma_period))
            sub.set_xlabel('Aggregate Particle Index')
            sub.set_ylabel('Boundary Collisions')
            sub.legend()
        else:
            agg = aggregate.as_ndarray()
            max_x = aggregate.max_x
            max_y = aggregate.max_y
            sub.set_xlim(-max_x * scalefactor, max_x * scalefactor)
            sub.set_ylim(-max_y * scalefactor, max_y * scalefactor)
            sub.scatter(agg[:, 0], agg[:, 1], c=aggregate.colors, s=4 * np.pi)
            sub.set_xlabel('x')
            sub.set_ylabel('y')
    fig.show()
    if save:
        fig.savefig(filename)
コード例 #5
0
ファイル: dla2d_tests.py プロジェクト: sjrowlinson/droplet
def point_attractor_test(nparticles, lattice_type, stickiness=1.0):
    """Generate an aggregate of `nparticles` on a specified lattice with
    a single point attractor as the initial seed.

    Parameters:
    -----------
    nparticles -- Number of particles to generate.
    lattice_type -- Type of lattice.
    stickiness -- Stickiness value of the aggregate [default 1.0].
    """
    point_agg = drp.Aggregate2D(stickiness=stickiness,
                                lattice_type=lattice_type)
    point_agg.generate(nparticles)
    plot_aggregate2d(point_agg, scalefactor=2.5)
コード例 #6
0
ファイル: dla2d_tests.py プロジェクト: sjrowlinson/droplet
def circle_attractor_test(nparticles, lattice_type, attradius, stickiness=1.0):
    """Generate an aggregate of `nparticles` on a specified lattice with
    a circle of `attradius` in size as the initial seed.

    Parameters:
    -----------
    nparticles -- Number of particles to generate.
    lattice_type -- Type of lattice.
    stickiness -- Stickiness value of the aggregate [default 1.0].
    """
    circle_agg = drp.Aggregate2D(stickiness=stickiness,
                                 lattice_type=lattice_type,
                                 attractor_type=drp.AttractorType.CIRCLE)
    circle_agg.attractor_size = attradius
    circle_agg.generate(nparticles)
    plot_aggregate2d(circle_agg)