.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/elliptic_lcs/plot_bickley_elliptic_lcs.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_elliptic_lcs_plot_bickley_elliptic_lcs.py: Bickley jet Elliptic LCS ======================== Compute the LAVD-based elliptic lcs for the bickley jet. .. GENERATED FROM PYTHON SOURCE LINES 8-25 .. code-block:: Python # Author: ajarvis import numpy as np from math import copysign, pi import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation from numbacs.flows import ( get_predefined_flow, get_predefined_callable, get_interp_arrays_scalar, get_callable_scalar, ) from numbacs.integration import flowmap_n_grid_2D, flowmap_n from numbacs.diagnostics import lavd_grid_2D from numbacs.extraction import rotcohvrt from numbacs.utils import curl_func_tspan, gen_filled_circ, interp_curve, pts_in_poly_mask .. GENERATED FROM PYTHON SOURCE LINES 26-30 Get flow -------------- Set the integration span and direction, retrieve the flow, jit-callable for velocity field, and set up domain. .. GENERATED FROM PYTHON SOURCE LINES 30-55 .. code-block:: Python # set initial time, integration time, integration direction, # and integration span (units of days) t0 = 0.0 T = 40.0 int_direction = copysign(1, T) n = 801 # retrieve function pointer and parameters for bickley jet flow. funcptr, params = get_predefined_flow( "bickley_jet", int_direction=int_direction, return_domain=False ) # retrieve callable to compute vorticity vel_spline = get_predefined_callable("bickley_jet", return_domain=False) # set up larger domain to capture all elliptic lcs domain = ((-2.0, 6.371 * pi + 2.0), (-3.0, 3.0)) dx = 0.05 dy = 0.05 x = np.arange(domain[0][0], domain[0][1] + dx, dx) y = np.arange(domain[1][0], domain[1][1] + dy, dy) nx = len(x) ny = len(y) .. GENERATED FROM PYTHON SOURCE LINES 56-59 Integrate --------- Integrate grid of particles and return positions at n times between [t0,t0+T] (inclusive). .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: Python flowmap, tspan = flowmap_n_grid_2D(funcptr, t0, T, x, y, params, n=n) .. GENERATED FROM PYTHON SOURCE LINES 62-65 Vorticity --------- Copmute vorticity on the grid and over the times for which the flowmap was returned. .. GENERATED FROM PYTHON SOURCE LINES 65-70 .. code-block:: Python # compute vorticity and create interpolant for it vort = curl_func_tspan(vel_spline, tspan, x, y, h=1e-3) grid_domain, C_vort = get_interp_arrays_scalar(tspan, x, y, vort) vort_spline = get_callable_scalar(grid_domain, C_vort) .. GENERATED FROM PYTHON SOURCE LINES 71-74 LAVD ---- Compute LAVD from vorticity and particle positions. .. GENERATED FROM PYTHON SOURCE LINES 74-87 .. code-block:: Python # need to pass raveled arrays into lavd_grid_2D X, Y = np.meshgrid(x, y, indexing="ij") xrav = X.ravel() yrav = Y.ravel() # since bickley jet is periodic in x-direction, need to pass its period # into lavd_grid_2D period_x = 6.371 * pi # compute lavd lavd = lavd_grid_2D(flowmap, tspan, T, vort_spline, xrav, yrav, period_x=period_x) .. GENERATED FROM PYTHON SOURCE LINES 88-91 LAVD-based elliptic LCS ----------------------- Compute elliptic LCS from LAVD. .. GENERATED FROM PYTHON SOURCE LINES 91-96 .. code-block:: Python # set parameters and compute lavd-based elliptic lcs r = 2.5 convexity_deficiency = 4e-3 elcs = rotcohvrt(lavd, x, y, r, convexity_deficiency=convexity_deficiency) .. GENERATED FROM PYTHON SOURCE LINES 97-100 Plot ---- Plot the elliptic LCS over the LAVD field. .. GENERATED FROM PYTHON SOURCE LINES 100-110 .. code-block:: Python # sphinx_gallery_thumbnail_number = 1 fig, ax = plt.subplots(dpi=200) ax.contourf(x, y, lavd.T, levels=80) ax.set_aspect("equal") for rcv, c in elcs: ax.plot(rcv[:, 0], rcv[:, 1], lw=1.5) ax.scatter(c[0], c[1], 1.5) plt.show() .. image-sg:: /auto_examples/elliptic_lcs/images/sphx_glr_plot_bickley_elliptic_lcs_001.png :alt: plot bickley elliptic lcs :srcset: /auto_examples/elliptic_lcs/images/sphx_glr_plot_bickley_elliptic_lcs_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 111-115 Advect elliptic LCS ------------------- Advect an elliptic LCS and nearby filled circle of points to demonstrate coherence. .. GENERATED FROM PYTHON SOURCE LINES 115-134 .. code-block:: Python # pick an elliptic lcs and create more refined curve by interpolating # we pick index 2 because it is the first not on a boundary of the domain, # any could be choosen c0 = elcs[2][1] rcv0 = elcs[2][0] rcvi = interp_curve(rcv0, 2500, per=1) # create a filled circle which has a center a distance delta away from # vortex center delta = 5e-1 circ_delta = gen_filled_circ(1.5, 10000, c=c0 + delta) # advect both the elliptic lcs and the nearby filled circle frames = 401 adv_rcv, teval = flowmap_n(funcptr, t0, T, rcvi, params, n=frames) adv_circ, _ = flowmap_n(funcptr, t0, T, circ_delta, params, n=frames) .. GENERATED FROM PYTHON SOURCE LINES 135-138 Animate ------- Create animation of advected elliptic LCS and nearby filled circle. .. GENERATED FROM PYTHON SOURCE LINES 138-185 .. code-block:: Python # find which points from the filled circle are inside elliptic lcs # for plotting purposes mask = pts_in_poly_mask(rcv0, circ_delta) # create plot fig, ax = plt.subplots(dpi=100) scatter0 = ax.scatter(adv_rcv[:, 0, 0] % period_x, adv_rcv[:, 0, 1], 1) scatter_in = ax.scatter( adv_circ[mask, 0, 0] % period_x, adv_circ[mask, 0, 1], 0.5, "purple", zorder=0 ) scatter_out = ax.scatter( adv_circ[~mask, 0, 0] % period_x, adv_circ[~mask, 0, 1], 0.5, "orange", zorder=0 ) ax.set_xlim([domain[0][0] + 2, domain[0][1] - 2]) ax.set_ylim([domain[1][0], domain[1][1]]) ax.set_aspect("equal") ax.set_title(f"t = {round(teval[0], 1)} days") # function for animation def update(frame): # for each frame, update the data stored on each artist x0 = adv_rcv[:, frame, 0] % period_x y0 = adv_rcv[:, frame, 1] x_in = adv_circ[mask, frame, 0] % period_x y_in = adv_circ[mask, frame, 1] x_out = adv_circ[~mask, frame, 0] % period_x y_out = adv_circ[~mask, frame, 1] data0 = np.column_stack((x0, y0)) data_in = np.column_stack((x_in, y_in)) data_out = np.column_stack((x_out, y_out)) # update each scatter plot scatter0.set_offsets(data0) scatter_in.set_offsets(data_in) scatter_out.set_offsets(data_out) # update title ax.set_title(f"t = {round(teval[frame], 1)} days") return (scatter0, scatter_in, scatter_out) # create animation ani = FuncAnimation(fig=fig, func=update, frames=frames, interval=50) plt.show() .. container:: sphx-glr-animation .. raw:: html
.. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 59.318 seconds) .. _sphx_glr_download_auto_examples_elliptic_lcs_plot_bickley_elliptic_lcs.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_bickley_elliptic_lcs.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_bickley_elliptic_lcs.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_bickley_elliptic_lcs.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_