.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/hyp_lcs/plot_dg_hyp_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_hyp_lcs_plot_dg_hyp_lcs.py: Double gyre Hyperbolic LCS ========================== Compute hyperbolic LCS using the variational theory for the double gyre. .. GENERATED FROM PYTHON SOURCE LINES 8-18 .. code-block:: Python # Author: ajarvis import numpy as np from math import copysign from numbacs.flows import get_predefined_flow from numbacs.integration import flowmap_aux_grid_2D from numbacs.diagnostics import C_eig_aux_2D, ftle_from_eig from numbacs.extraction import hyperbolic_lcs import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 19-22 Get flow -------------- Set the integration span and direction, retrieve the flow, and set up domain. .. GENERATED FROM PYTHON SOURCE LINES 22-38 .. code-block:: Python # set initial time, integration time, and integration direction t0 = 0.0 T = -10.0 int_direction = copysign(1, T) # retrieve function pointer and parameters for double gyre flow. funcptr, params, domain = get_predefined_flow("double_gyre", int_direction=int_direction) # set up domain nx, ny = 401, 201 x = np.linspace(domain[0][0], domain[0][1], nx) y = np.linspace(domain[1][0], domain[1][1], ny) dx = x[1] - x[0] dy = y[1] - y[0] .. GENERATED FROM PYTHON SOURCE LINES 39-42 Integrate --------- Integrate grid of particles and auxillary grid with spacing h, return final positions .. GENERATED FROM PYTHON SOURCE LINES 42-48 .. code-block:: Python # computes final position of particle trajectories over grid + auxillary grid # with spacing h h = 1e-5 flowmap = flowmap_aux_grid_2D(funcptr, t0, T, x, y, params, h=h) .. GENERATED FROM PYTHON SOURCE LINES 49-52 CG eigenvalues, eigenvectors, and FTLE ---------------------------------------------- Compute eigenvalues/vectors of CG tensor from final particle positions and compute FTLE. .. GENERATED FROM PYTHON SOURCE LINES 52-60 .. code-block:: Python # compute eigenvalues/vectors of Cauchy Green tensor eigvals, eigvecs = C_eig_aux_2D(flowmap, dx, dy, h=h) eigval_max = eigvals[:, :, 1] eigvec_max = eigvecs[:, :, :, 1] # copmute FTLE from max eigenvalue ftle = ftle_from_eig(eigval_max, T) .. GENERATED FROM PYTHON SOURCE LINES 61-64 Hyperbolic LCS -------------- Compute hyperbolic LCS using the variational theory. .. GENERATED FROM PYTHON SOURCE LINES 64-100 .. code-block:: Python # set parameters for hyperbolic lcs extraction, # see function description for more details step_size = 1e-3 steps = 3000 lf = 0.1 lmin = 1.5 r = 0.1 nmax = -1 dtol = 1e-1 nlines = 10 percentile = 40 ep_dist_tol = 1e-2 lambda_avg_min = 600 arclen_flag = True # extract hyperbolic lcs lcs = hyperbolic_lcs( eigval_max, eigvecs, x, y, step_size, steps, lf, lmin, r, nmax, dist_tol=dtol, nlines=nlines, ep_dist_tol=ep_dist_tol, percentile=percentile, lambda_avg_min=lambda_avg_min, arclen_flag=arclen_flag, ) .. GENERATED FROM PYTHON SOURCE LINES 101-104 Plot ---- Plot the results. .. GENERATED FROM PYTHON SOURCE LINES 104-110 .. code-block:: Python fig, ax = plt.subplots(dpi=200) ax.contourf(x, y, ftle.T, levels=80) for l in lcs: ax.plot(l[:, 0], l[:, 1], "r", lw=1) ax.set_aspect("equal") plt.show() .. image-sg:: /auto_examples/hyp_lcs/images/sphx_glr_plot_dg_hyp_lcs_001.png :alt: plot dg hyp lcs :srcset: /auto_examples/hyp_lcs/images/sphx_glr_plot_dg_hyp_lcs_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 29.687 seconds) .. _sphx_glr_download_auto_examples_hyp_lcs_plot_dg_hyp_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_dg_hyp_lcs.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_dg_hyp_lcs.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_dg_hyp_lcs.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_