|
| 1 | +"""Calculate and plot the Lyapunov Spectra of all three-dimensional chaotic flows.""" |
| 2 | + |
| 3 | +import matplotlib.pyplot as plt |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +from lorenzpy import measures as meas |
| 7 | +from lorenzpy import simulations as sims |
| 8 | + |
| 9 | +systems = [ |
| 10 | + "Lorenz63", |
| 11 | + "Chen", |
| 12 | + "ChuaCircuit", |
| 13 | + "ComplexButterfly", |
| 14 | + "DoubleScroll", |
| 15 | + "Halvorsen", |
| 16 | + "Roessler", |
| 17 | + "Rucklidge", |
| 18 | + "Thomas", |
| 19 | + "WindmiAttractor", |
| 20 | +] |
| 21 | + |
| 22 | +# Calculate exponents: |
| 23 | +m = 3 |
| 24 | +deviation_scale = 1e-10 |
| 25 | +steps = 1000 |
| 26 | +part_time_steps = 15 |
| 27 | +steps_skip = 50 |
| 28 | + |
| 29 | +solver = "rk4" |
| 30 | +# solver = sims.solvers.create_scipy_ivp_solver(method="RK45") |
| 31 | + |
| 32 | +lyap_dict = {} |
| 33 | +for i_sys, system in enumerate(systems): |
| 34 | + print(system) |
| 35 | + sys_obj = getattr(sims, system)(solver=solver) |
| 36 | + iterator_func = sys_obj.iterate |
| 37 | + starting_point = sys_obj.get_default_starting_pnt() |
| 38 | + dt = sys_obj.dt |
| 39 | + |
| 40 | + lyap_dict[system] = meas.lyapunov_exponent_spectrum( |
| 41 | + iterator_func=iterator_func, |
| 42 | + starting_point=starting_point, |
| 43 | + deviation_scale=deviation_scale, |
| 44 | + steps=steps, |
| 45 | + part_time_steps=part_time_steps, |
| 46 | + steps_skip=steps_skip, |
| 47 | + dt=dt, |
| 48 | + m=m, |
| 49 | + initial_pert_directions=None, |
| 50 | + return_convergence=True, |
| 51 | + ) |
| 52 | + |
| 53 | +fig, axs = plt.subplots( |
| 54 | + 2, 5, figsize=(15, 8), layout="constrained", sharex=True, sharey=False |
| 55 | +) |
| 56 | + |
| 57 | +# x and y titles: |
| 58 | +fig.supxlabel("Number of renormalization steps") |
| 59 | +fig.supylabel("Lyapunov exponent convergence") |
| 60 | + |
| 61 | +axs = axs.flatten() |
| 62 | +x = np.arange(1, steps + 1) |
| 63 | +for i_ax, ax in enumerate(axs): |
| 64 | + system = systems[i_ax] |
| 65 | + le_spectrum = lyap_dict[system] |
| 66 | + ax.title.set_text(system) |
| 67 | + ax.plot( |
| 68 | + x, |
| 69 | + le_spectrum, |
| 70 | + linewidth=1, |
| 71 | + ) |
| 72 | + ax.grid(True) |
| 73 | + |
| 74 | + final_les = np.round(le_spectrum[-1, :], 4).tolist() |
| 75 | + final_les = [str(x) for x in final_les] |
| 76 | + le_string = "\n".join(final_les) |
| 77 | + le_string = "Final LEs: \n" + le_string |
| 78 | + x_position = 0.1 # X-coordinate of the upper-left corner for each subplot |
| 79 | + y_position = 0.5 |
| 80 | + ax.text( |
| 81 | + x_position, |
| 82 | + y_position, |
| 83 | + le_string, |
| 84 | + fontsize=10, |
| 85 | + bbox=dict(facecolor="white", edgecolor="black", boxstyle="round"), |
| 86 | + verticalalignment="center", |
| 87 | + horizontalalignment="left", |
| 88 | + transform=ax.transAxes, |
| 89 | + ) |
| 90 | + |
| 91 | +plt.show() |
0 commit comments