예제 #1
0
def test_pseudo_interaction(runtime, dt):
    # A linear field where advected particles are moving at
    # 1 m/s in the longitudinal direction.
    xdim, ydim = (10, 20)
    Uflow = Field('U',
                  np.ones((ydim, xdim), dtype=np.float64),
                  lon=np.linspace(0., 1e3, xdim, dtype=np.float64),
                  lat=np.linspace(0., 1e3, ydim, dtype=np.float64))
    Vflow = Field('V',
                  np.zeros((ydim, xdim), dtype=np.float64),
                  grid=Uflow.grid)
    fieldset = FieldSet(Uflow, Vflow)

    # Execute the advection kernel only
    pset = ParticleSet(fieldset, pclass=ScipyParticle, lon=[2], lat=[2])
    pset.execute(AdvectionRK4, runtime=runtime, dt=dt)

    # Execute both the advection and interaction kernel.
    pset2 = ParticleSet(fieldset,
                        pclass=ScipyInteractionParticle,
                        lon=[2],
                        lat=[2],
                        interaction_distance=1)
    pyfunc_inter = pset2.InteractionKernel(ConstantMoveInteraction)
    pset2.execute(AdvectionRK4,
                  pyfunc_inter=pyfunc_inter,
                  runtime=runtime,
                  dt=dt)

    # Check to see whether they have moved as predicted.
    assert np.all(pset.lon == pset2.lon)
    assert np.all(pset2.lat == pset2.lon)
    assert np.all(
        pset2._collection.data["time"][0] == pset._collection.data["time"][0])
예제 #2
0
def test_concatenate_interaction_kernels(fieldset, mode):
    lons = [0.0, 0.1, 0.25, 0.44]
    lats = [0.0, 0.0, 0.0, 0.0]
    # Distance in meters R_earth*0.2 degrees
    interaction_distance = 6371000 * 0.2 * np.pi / 180

    pset = ParticleSet(fieldset,
                       pclass=ptype[mode],
                       lon=lons,
                       lat=lats,
                       interaction_distance=interaction_distance)
    pset.execute(DoNothing,
                 pyfunc_inter=pset.InteractionKernel(DummyMoveNeighbor) +
                 pset.InteractionKernel(DummyMoveNeighbor),
                 endtime=1.,
                 dt=1.)
    # The kernel results are only applied after all interactionkernels
    # have been executed, so we expect the result to be double the
    # movement from executing the kernel once.
    assert np.allclose(pset.lat, [0.2, 0.4, 0.1, 0.0], rtol=1e-5)
예제 #3
0
def test_neighbor_merge(fieldset, mode):
    lons = [0.0, 0.1, 0.25, 0.44]
    lats = [0.0, 0.0, 0.0, 0.0]
    # Distance in meters R_earth*0.2 degrees
    interaction_distance = 6371000 * 5.5 * np.pi / 180
    pset = ParticleSet(fieldset,
                       pclass=MergeParticle,
                       lon=lons,
                       lat=lats,
                       interaction_distance=interaction_distance)
    pyfunc_inter = (pset.InteractionKernel(NearestNeighborWithinRange) +
                    MergeWithNearestNeighbor)
    pset.execute(DoNothing, pyfunc_inter=pyfunc_inter, runtime=3., dt=1.)

    # After two steps, the particles should be removed.
    assert len(pset) == 1
예제 #4
0
def test_asymmetric_attraction(fieldset, mode):
    lons = [0.0, 0.1, 0.2]
    lats = [0.0, 0.0, 0.0]
    # Distance in meters R_earth*0.2 degrees
    interaction_distance = 6371000 * 5.5 * np.pi / 180
    pset = ParticleSet(fieldset,
                       pclass=AttractingParticle,
                       lon=lons,
                       lat=lats,
                       interaction_distance=interaction_distance,
                       attractor=[True, False, False])
    pyfunc_inter = pset.InteractionKernel(AsymmetricAttraction)
    pset.execute(DoNothing, pyfunc_inter=pyfunc_inter, runtime=3., dt=1.)

    assert lons[1] > pset.lon[1]
    assert lons[2] > pset.lon[2]
    assert len(pset) == 3