Exemple #1
0
def swater(
    n,
    timesteps,
    ):
    """Simulate shallow water movement following a drop"""

    dt = 0.02  # hard-wired timestep
    dx = 1.0
    dy = 1.0
    D = droplet(2.5, 10)  # simulate a water drop
    droploc = n / 4

    H = numpy.ones((n + 2, n + 2))
    U = numpy.zeros((n + 2, n + 2))
    V = numpy.zeros((n + 2, n + 2))
    Hx = numpy.zeros((n + 1, n + 1))
    Ux = numpy.zeros((n + 1, n + 1))
    Vx = numpy.zeros((n + 1, n + 1))
    Hy = numpy.zeros((n + 1, n + 1))
    Uy = numpy.zeros((n + 1, n + 1))
    Vy = numpy.zeros((n + 1, n + 1))

    (dropx, dropy) = D.shape
    H[droploc:droploc + dropx, droploc:droploc + dropy] += D

    evolve(timesteps, n, H, U, V, Hx, Hy, Ux, Uy, Vx, Vy, dx, dy, dt)
Exemple #2
0
def swater(
    n,
    timesteps,
    plotfreq,
    visual,
    ):
    """Simulate shallow water movement following a drop"""

    dt = 0.02  # hard-wired timestep
    dx = 1.0
    dy = 1.0
    D = droplet(2.5, 10)  # simulate a water drop
    droploc = n / 4

    H = numpy.ones((n + 2, n + 2))
    U = numpy.zeros((n + 2, n + 2))
    V = numpy.zeros((n + 2, n + 2))
    Hx = numpy.zeros((n + 1, n + 1))
    Ux = numpy.zeros((n + 1, n + 1))
    Vx = numpy.zeros((n + 1, n + 1))
    Hy = numpy.zeros((n + 1, n + 1))
    Uy = numpy.zeros((n + 1, n + 1))
    Vy = numpy.zeros((n + 1, n + 1))

    (dropx, dropy) = D.shape
    H[droploc:droploc + dropx, droploc:droploc + dropy] += D

    start = time.time()

    for _ in xrange(timesteps/plotfreq):
        visual.update(H[1:-1, 1:-1])
        evolve(plotfreq, n, H, U, V, Hx, Hy, Ux, Uy, Vx, Vy, dx, dy, dt)
    stop = time.time()
    visual.end()

    return stop - start