Beispiel #1
0
def iterate(field, field0, timesteps, image_interval):
    nx, ny = field.shape
    fieldprt = ffi.cast("double *", ffi.from_buffer(field))
    field0prt = ffi.cast("double *", ffi.from_buffer(field0))
    for m in range(1, timesteps + 1):
        lib.evolve(fieldprt, field0prt, nx, ny, a, dt, dx2, dy2)
        if m % image_interval == 0:
            write_field(field, m)
Beispiel #2
0
def evolve(u, u_previous, a, dt, dx2, dy2):
    """Explicit time evolution.
       u:            new temperature field
       u_previous:   previous field
       a:            diffusion constant
       dt:           time step. """

    u_ptr = ffi.cast("double *", ffi.from_buffer(u))
    u_previous_ptr = ffi.cast("double *", ffi.from_buffer(u_previous))
    nx, ny = u.shape
    lib.evolve(u_ptr, u_previous_ptr, nx, ny, a, dt, dx2, dy2)
Beispiel #3
0
def iterate(field, field0, a, dx, dy, timesteps, image_interval):
    """Run fixed number of time steps of heat equation"""

    dx2 = dx**2
    dy2 = dy**2

    # For stability, this is the largest interval possible
    # for the size of the time-step:
    dt = dx2 * dy2 / (2 * a * (dx2 + dy2))
    nx, ny = field.shape

    field_ptr = ffi.cast("double *", ffi.from_buffer(field))
    field0_ptr = ffi.cast("double *", ffi.from_buffer(field0))

    for m in range(1, timesteps + 1):
        lib.evolve(field_ptr, field0_ptr, nx, ny, a, dt, dx2, dy2)
        if m % image_interval == 0:
            write_field(field, m)