Esempio n. 1
0
def ftle_phot(nx, ny, int_time, t_0):
    #~~~~~~~~~~~~~~ INITIALISE PARAMETERS ~~~~~~~~~~~~~~~~~~~~~
    dt_min = np.sign(int_time) * 1
    dt_max = np.sign(int_time) * 200
    etol = 0.1

    # ~~~~~~~~~~~~~~  RESTRICT GRID DOMAIN ~~~~~~~~~~~~~~
    grid_lim_step = 4
    X_min, X_max, Y_min, Y_max = (X[grid_lim_step], X[-grid_lim_step - 1],
                                  Y[grid_lim_step], Y[-grid_lim_step - 1]
                                  )  # Limit initial grid size
    aux_grid_spacing = ((X_max - X_min) / nx) * 0.08
    # Compute nx*ny grid of coordinates
    xx = np.linspace(X_min, X_max, nx)
    yy = np.linspace(Y_min, Y_max, ny)
    coord_grid = np.array(np.meshgrid(xx, yy, indexing='xy'))
    # Compute auxiliary grid for differentiation
    aux_grid = fn.generate_auxiliary_grid(coord_grid, aux_grid_spacing)
    # Perform RKF45 scheme on aux_grid
    t_beforeloop = time.time()
    final_positions = ODE.dp45_loop(derivs=interp.regular_grid_interpolator_fn(
        U, V, X, Y, TIME)[1],
                                    aux_grid=aux_grid,
                                    t_0=t_0,
                                    int_time=int_time,
                                    dt_min=dt_min,
                                    dt_max=dt_max,
                                    maxiters=1000,
                                    atol=etol,
                                    rtol=etol)  #00001)
    # final_positions = fn.rk4_loop(
    #     derivs=interp.regular_grid_interpolator_fn(U, V, X, Y, TIME)[1], aux_grid=aux_grid,
    #     t_0=t_0,
    #     int_time=int_time, dt = 250,return_data=False)
    t_afterloop = time.time()
    print "Time taken to integrate ODE:", t_afterloop - t_beforeloop

    jac = fn.jacobian_matrix_aux(final_positions,
                                 aux_grid_spacing=aux_grid_spacing)
    cgst = fn.cauchy_green_tensor(jac)
    ev = np.linalg.eigvalsh(cgst)
    ev_max = np.amax(ev, -1)
    ftle = np.log(ev_max) / (2. * np.abs(int_time))
    time_label = 'T = %+d h' % (int_time / 3600.)

    return ftle, X_min, X_max, Y_min, Y_max, time_label
Esempio n. 2
0
def plot_phot(int_time, t_0=TIME[0], g=1, s=0.7, r=1.2, sat=1):
    #~~~~~~~~~~~~~~ INITIALISE PARAMETERS ~~~~~~~~~~~~~~~~~~~~~
    nx = 400
    ny = nx
    # t_0 = TIME[0]                  # Initial time
    # int_time  = 400 # in seconds (21600s = 6 hrs)
    dt_min = np.sign(int_time) * 1
    dt_max = np.sign(int_time) * 200
    etol = 0.1
    # ~~~~~~~~~~~~~~  SETUP UNITS ~~~~~~~~~~~~~~
    lenunits = 'km'  #units of distance for axis labels
    INIT_TIME = 1165933440.0  # Epoch time (rel to Jan 1 1970) in seconds of Dec 12 2006 (initial time of magnetograms)
    # print time.strftime('%d-%b-%Y %H:%M GMT', time.gmtime(INIT_TIME))
    REF_TIME = INIT_TIME - TIME[0]
    # ~~~~~~~~~~~~~~  RESTRICT GRID DOMAIN ~~~~~~~~~~~~~~
    grid_lim_step = 4
    X_min, X_max, Y_min, Y_max = (X[grid_lim_step], X[-grid_lim_step - 1],
                                  Y[grid_lim_step], Y[-grid_lim_step - 1]
                                  )  # Limit initial grid size
    aux_grid_spacing = ((X_max - X_min) / nx) * 0.08
    # Compute nx*ny grid of coordinates
    xx = np.linspace(X_min, X_max, nx)
    yy = np.linspace(Y_min, Y_max, ny)
    coord_grid = np.array(np.meshgrid(xx, yy, indexing='xy'))
    # Compute auxiliary grid for differentiation
    aux_grid = fn.generate_auxiliary_grid(coord_grid, aux_grid_spacing)
    # Perform RKF45 scheme on aux_grid
    t_beforeloop = time.time()
    final_positions = ODE.dp45_loop(derivs=interp.regular_grid_interpolator_fn(
        U, V, X, Y, TIME)[1],
                                    aux_grid=aux_grid,
                                    t_0=t_0,
                                    int_time=int_time,
                                    dt_min=dt_min,
                                    dt_max=dt_max,
                                    maxiters=1000,
                                    atol=etol,
                                    rtol=etol)  #00001)
    # final_positions = fn.rk4_loop(
    #     derivs=interp.regular_grid_interpolator_fn(U, V, X, Y, TIME)[1], aux_grid=aux_grid,
    #     t_0=t_0,
    #     int_time=int_time, dt = 250,return_data=False)
    t_afterloop = time.time()
    print "Time taken to integrate ODE:", t_afterloop - t_beforeloop

    jac = fn.jacobian_matrix_aux(final_positions,
                                 aux_grid_spacing=aux_grid_spacing)
    cgst = fn.cauchy_green_tensor(jac)
    ev = np.linalg.eigvalsh(cgst)
    ev_max = np.amax(ev, -1)
    ftle = np.log(ev_max) / (2. * np.abs(int_time))

    time_label = 'T = %+.1f h' % (int_time / 3600.)
    # Plotting code for plot of eigenvalues/FTLE field
    #labtop path
    # Google drive path
    plot_name = "C:/Users/Harry/Google Drive/Project IV Lagrangian Coherent Structures/plots/phot/nx%r_t0rel%.1f_T%r_etol%r_dp45.pdf" % (
        nx, t_0 - TIME[0], int_time, etol)
    plot.FTLE_plot(ftle,
                   X_min,
                   X_max,
                   Y_min,
                   Y_max,
                   int_time=0,
                   t_0=0,
                   adap_error_tol=0,
                   colour_range=(-0.0001, 0.0001),
                   colour_rescale=0,
                   save_name=plot_name,
                   g=g,
                   s=s,
                   r=r,
                   sat=sat,
                   lenunits=lenunits,
                   label1=time.strftime('%d-%b-%Y %H:%M UT',
                                        time.gmtime((t_0 + REF_TIME))),
                   label2=time_label)
Esempio n. 3
0
# Perform RKF45 scheme on aux_grid
# final_positions = fn.rkf45_loop_fixed_step(
#     derivs=regular_grid_interpolator_fn(U_hyd, V_hyd, X, Y, TIME_hyd)[1], aux_grid=aux_grid,
#     adaptive_error_tol=adap_error_tol, t_0=t_0,
#     int_time=int_time, dt_min=dt_min, dt_max = dt_max)
# final_positions = fn.rk4_loop(
#     derivs=regular_grid_interpolator_fn(U_hyd, V_hyd, X, Y, TIME_hyd)[1], aux_grid=aux_grid,
#     t_0=t_0,
#     int_time=int_time, dt = 0.2,return_data=False)
# NEW RKF45 SCHEME
final_positions = ODE.dp45_loop(derivs=interp.regular_grid_interpolator_fn(U_hyd, V_hyd, X, Y, TIME_hyd)[1], aux_grid=aux_grid,
    t_0=t_0, int_time=int_time, dt_min=dt_min,dt_max= dt_max,
    maxiters = 1000, atol = adaptive_error_tol, rtol = adaptive_error_tol)

t_afterloop = time.time()

print "Time taken to integrate ODE:", t_afterloop - t_beforeloop

#print final_positions
jac = fn.jacobian_matrix_aux(final_positions,aux_grid_spacing=aux_grid_spacing)
cgst = fn.cauchy_green_tensor(jac)
ev = np.linalg.eigvalsh(cgst)
ev_max = np.amax(ev,-1)
#print ev_max, np.average(ev_max)
ftle = np.log(ev_max)/(2.*np.abs(int_time))


#
# Plotting code for plot of eigenvalues/FTLE field
plot.FTLE_plot(ftle, X_min, X_max, Y_min, Y_max, int_time=0, t_0=0, adap_error_tol=0, colour_range=(-1.5,1.5), save_name = "sim_ftle_bwd_T-2_limclr.pdf")
Esempio n. 4
0
def main(amplitude,
         epsilon,
         omega,
         nx,
         ny,
         aux_grid_spacing,
         t_0,
         int_time,
         adaptive_error_tol,
         dt_min,
         dt_max,
         method='rkf45'):
    '''
	Main function that puts together other functions to compute the FTLE field of the double gyre
	~~~~~~~~~~
	Inputs:
	==
	double-gyre parameters:
	amplitude = amplitude of oscillations
	epsilon = amplitude of time dependent perturbations
	omega = angular frequency of double gyre system
	==
	general parameters:
	nx = # points of original grid in x-direction
	ny = # points of original grid in y-direction
	aux_grid_spacing = spacing of the auxiliary grid from the original grid used for finite differencing
	t_0 = initial time to start integration at
	int_time = time integrated over
	adaptive_error_tol = error tolerance used in the adaptive timestep integration scheme
	method = method used for numerical integration -- currently only supports rkf45 fixed
	~~~~~~~~~~
	Outputs:
	ftle = the finite-time Lyapunov exponent for the double gyre in a ny*nx array
	ev = eigenvalues of the Cauchy-Green strain tensor
	'''
    # Globalise double gyre parameters (for convenience of using analytic_velocity in rkf45 loop)
    dg_params = gyre_global_params(amplitude=amplitude,
                                   epsilon=epsilon,
                                   omega=omega)
    #~~gen_params = fn.general_params(nx=nx, ny=ny, aux_grid_spacing=aux_grid_spacing, adaptive_error_tol=adaptive_error_tol, t_0=t_0, int_time=int_time, dt_i=dt_i)

    a_grid = fn.generate_auxiliary_grid(generate_grid(nx, ny),
                                        aux_grid_spacing=aux_grid_spacing)
    #~~print np.shape(a_grid)

    if method == 'rkf45_fixed':
        # Perform rkf45 loop for fixed step on all grid points
        final_pos = fn.rkf45_loop_fixed_step(
            derivs=analytic_velocity,
            aux_grid=a_grid,
            adaptive_error_tol=adaptive_error_tol,
            t_0=t_0,
            int_time=int_time,
            dt_min=dt_min,
            dt_max=dt_max)
        print "RKF45 fixed time step method used"

    if method == 'rk4':
        # Perform rk4 loop procedure

        print "RK4 method used"

    if method == 'rkf45':
        print "OLD VERSION OF RKF45 USED WHERE NO RESTEPPING OCCURS"
        final_pos = fn.rkf45_loop(derivs=analytic_velocity,
                                  aux_grid=a_grid,
                                  adaptive_error_tol=adaptive_error_tol,
                                  t_0=t_0,
                                  int_time=int_time,
                                  dt_min=dt_min,
                                  dt_max=dt_max)
        print "OLD VERSION OF RKF45 USED WHERE NO RESTEPPING OCCURS"

        print "RKF45 full adaptive grid method used"

    if method == 'rkf45error':
        final_pos = ODE.rkf45_loop(derivs=analytic_velocity,
                                   aux_grid=a_grid,
                                   t_0=t_0,
                                   int_time=int_time,
                                   dt_min=dt_min,
                                   dt_max=dt_max,
                                   maxiters=1000,
                                   atol=adaptive_error_tol,
                                   rtol=adaptive_error_tol)

    if method == 'dp45':
        final_pos = ODE.dp45_loop(derivs=analytic_velocity,
                                  aux_grid=a_grid,
                                  t_0=t_0,
                                  int_time=int_time,
                                  dt_min=dt_min,
                                  dt_max=dt_max,
                                  maxiters=1000,
                                  atol=adaptive_error_tol,
                                  rtol=adaptive_error_tol)
    # Calculate jacobian matrix
    jac = fn.jacobian_matrix_aux(final_pos, aux_grid_spacing=aux_grid_spacing)
    cgst = fn.cauchy_green_tensor(jac)

    ev = np.linalg.eigvalsh(cgst)
    ev_max = np.amax(ev, -1)
    ftle = np.log(ev_max) / (2. * np.abs(int_time))

    return ftle