コード例 #1
0
    def test_differential_correction(self):
        """ Test solution obtained using differential correction """

        MASS_A = 1.0
        MASS_B = 1.0

        SADDLE_ENERGY = 0.0  # Energy of the saddle
        ALPHA = 1.00
        BETA = 1.00
        OMEGA = 1
        EPSILON = 0.00  # uncoupled
        parameters = np.array([MASS_A, MASS_B, SADDLE_ENERGY, \
                            ALPHA, BETA, OMEGA, EPSILON])

        deltaE_vals = [0.1]
        linecolors = ['b']
        save_final_plot = False
        show_final_plot = True
        diff_corr_unc.upo(deltaE_vals, linecolors, \
                            save_final_plot, show_final_plot)

        TSPAN = [0, 30]  # arbitrary range, just to finish the integration
        RelTol = 3.e-12
        AbsTol = 1.e-12

        for deltaE_val in deltaE_vals:
            # po_fam_file = "x0_diffcorr_deltaE%s_uncoupled.dat" %(deltaE_val)
            with open(path_to_data + "x0_diffcorr_deltaE%s_uncoupled.dat" %
                      (deltaE_val)) as po_fam_file:
                x0podata = np.loadtxt(po_fam_file.name)
                x0po_diffcorr = x0podata[0:4]
                # print(x0po_diffcorr)

            f = lambda t, x: uncoupled.ham2dof_uncoupled(t, x, parameters)
            soln = solve_ivp(f, TSPAN, x0po_diffcorr,method='RK45',dense_output=True, \
                 events = lambda t,x : uncoupled.half_period_uncoupled(t,x,parameters), \
                 rtol=RelTol, atol=AbsTol)

            te = soln.t_events[0]
            tt = [0, te[2]]
            t,x_diffcorr,phi_t1,PHI = diffcorr.state_transit_matrix(
                tt, x0po_diffcorr, parameters, \
                uncoupled.variational_eqns_uncoupled)

            total_energy = deltaE_val + parameters[2]
            y, py = uncoupled.upo_analytical(total_energy, t, parameters)

            numerical_orbit = np.array([x_diffcorr[:, 1], x_diffcorr[:, 3]])
            analytical_orbit = np.array([y, py])

            np.testing.assert_array_almost_equal(numerical_orbit,
                                                 analytical_orbit)

            hausd_dist = hausd_dist_numeric_analytic(x_diffcorr, t, deltaE_val,
                                                     parameters)
            self.assertLessEqual(hausd_dist, 1e-8)
コード例 #2
0
#%% Integrate the Hamilton's equations w.r.t the initial conditions
# for the full period T and plot the UPOs

TSPAN = [0, 30]
plt.close('all')
axis_fs = 15
RelTol = 3.e-10
AbsTol = 1.e-10

f = lambda t, x: deleonberne.ham2dof_deleonberne(t, x, parameters)
soln = solve_ivp(f, TSPAN, x0po[0,0:4],method='RK45',dense_output=True, \
                 events = lambda t,x : deleonberne.half_period_deleonberne(t,x,parameters), \
                 rtol=RelTol, atol=AbsTol)
te = soln.t_events[0]
tt = [0, te[2]]
t,x_diffcorr,phi_t1,PHI = diffcorr.state_transit_matrix(tt, x0po[0,0:4], parameters, \
                                                        deleonberne.variational_eqns_deleonberne)


soln = solve_ivp(f, TSPAN, x0po[1,0:4], method='RK45',dense_output=True, \
                 events = lambda t,x : deleonberne.half_period_deleonberne(t,x,parameters), \
                 rtol=RelTol, atol=AbsTol)
te = soln.t_events[0]
tt = [0, te[2]]
t,x_turningpoint,phi_t1,PHI = diffcorr.state_transit_matrix(tt, x0po[1,0:4], parameters, \
                                                            deleonberne.variational_eqns_deleonberne)


soln = solve_ivp(f, TSPAN, x0po[2,0:4], method='RK45', dense_output=True, \
                 events = lambda t,x : deleonberne.half_period_deleonberne(t,x,parameters), \
                 rtol=RelTol, atol=AbsTol)
te = soln.t_events[0]
コード例 #3
0
AbsTol = 1.e-10

plt.close('all')
axis_fs = 15
figh = plt.figure(figsize=(6, 6))

for i in range(len(deltaE_vals)):
    deltaE = deltaE_vals[i]
    f = lambda t, x: deleonberne.ham2dof_deleonberne(t, x, parameters)
    soln = solve_ivp(f, TSPAN, x0po[:,i],method='RK45',dense_output=True, \
                     events = lambda t,x : deleonberne.half_period_deleonberne(t,x,parameters), \
                     rtol=RelTol, atol=AbsTol)

    te = soln.t_events[0]
    tt = [0, te[1]]
    t,x,phi_t1,PHI = diffcorr.state_transit_matrix(tt,x0po[:,i],parameters, \
                                            deleonberne.variational_eqns_deleonberne)
    ax = plt.gca(projection='3d')
    ax.plot(x[:,0],x[:,1],x[:,2],'-',color = linecolor[i], \
        label = '$\Delta E$ = %.2f'%(deltaE))
    ax.plot(x[:, 0], x[:, 1], -x[:, 2], '-', color=linecolor[i])
    ax.scatter(x[0, 0], x[0, 1], x[0, 2], s=10, marker='*')
    ax.scatter(x[0, 0], x[0, 1], -x[0, 2], s=10, marker='o')
    ax.plot(x[:, 0], x[:, 1], zs=0, zdir='z')

resX = 100
xVec = np.linspace(-1, 1, resX)
yVec = np.linspace(-2, 2, resX)
xMat, yMat = np.meshgrid(xVec, yVec)
cset1 = ax.contour(
        xMat, yMat, diffcorr.get_pot_surf_proj(
            xVec, yVec, deleonberne.pot_energy_deleonberne, \
コード例 #4
0
plt.close('all')
figH = plt.figure(figsize=(7, 7))
ax = figH.gca(projection='3d')
axis_fs = 15

for i in range(len(deltaE_vals)):
    deltaE = deltaE_vals[i]
    f = lambda t, x: coupled.ham2dof_coupled(t, x, parameters)
    soln = solve_ivp(f, TSPAN, x0po[:,i],method='RK45',dense_output=True, \
                     events = lambda t,x : coupled.half_period_coupled(t,x,parameters), \
                     rtol=RelTol, atol=AbsTol)

    te = soln.t_events[0]
    tt = [0, te[1]]
    t,x,phi_t1,PHI = diffcorr.state_transit_matrix(tt,x0po[:,i], \
                                            parameters, \
                                            coupled.variational_eqns_coupled)




    ax.plot(x[:,0],x[:,1],x[:,3],'-',color = linecolor[i], \
            label = '$\Delta E$ = %.2f'%(deltaE))
    ax.plot(x[:, 0], x[:, 1], -x[:, 3], '-', color=linecolor[i])
    ax.scatter(x[0, 0], x[0, 1], x[0, 3], s=10, marker='*')
    ax.scatter(x[0, 0], x[0, 1], -x[0, 3], s=10, marker='o')

# Plotting equipotential lines
resX = 100
xVec = np.linspace(-4, 4, resX)
yVec = np.linspace(-4, 4, resX)
コード例 #5
0
#%% Integrate the Hamilton's equations w.r.t the initial conditions for the full period T and plot the UPOs 

TSPAN = [0,30]
plt.close('all')
axis_fs = 15
RelTol = 3.e-10
AbsTol = 1.e-10


f = lambda t,x: coupled.ham2dof_coupled(t,x,parameters)
soln = solve_ivp(f, TSPAN, x0po[0,0:4],method='RK45',dense_output=True, \
                 events = lambda t,x : coupled.half_period_coupled(t,x,parameters), \
                 rtol=RelTol, atol=AbsTol)
te = soln.t_events[0]
tt = [0,te[2]]
t,x_diffcorr,phi_t1,PHI = diffcorr.state_transit_matrix(tt, x0po[0,0:4], parameters, \
                                                        coupled.variational_eqns_coupled)



f = lambda t,x: coupled.ham2dof_coupled(t,x,parameters)
soln = solve_ivp(f, TSPAN, x0po[1,0:4], method='RK45',dense_output=True, \
                 events = lambda t,x : coupled.half_period_coupled(t,x,parameters), \
                 rtol=RelTol, atol=AbsTol)
te = soln.t_events[0]
tt = [0,te[2]]
t,x_turningpoint,phi_t1,PHI = diffcorr.state_transit_matrix(tt, x0po[1,0:4], parameters, \
                                                            coupled.variational_eqns_coupled)


f= lambda t,x: coupled.ham2dof_coupled(t,x,parameters)
soln = solve_ivp(f, TSPAN, x0po[2,0:4], method='RK45', dense_output=True, \
コード例 #6
0
def upo(deltaE_vals, linecolor, \
        save_final_plot = True, show_final_plot = False):
    #%% Setting up parameters and global variables

    eqPt = diffcorr.get_eq_pts(eqNum, uncoupled.init_guess_eqpt_uncoupled, \
                                uncoupled.grad_pot_uncoupled, \
                                parameters)

    #energy of the saddle eq pt
    eSaddle = diffcorr.get_total_energy([eqPt[0],eqPt[1],0,0], \
                                        uncoupled.pot_energy_uncoupled, \
                                        parameters)

    #%%
    nFam = 100  # use nFam = 10 for low energy

    # first two amplitudes for continuation procedure to get p.o. family
    Ax1 = 2.e-5  # initial amplitude (1 of 2) values to use: 2.e-3
    Ax2 = 2 * Ax1  # initial amplitude (2 of 2)

    t = time.time()

    # get the initial conditions and periods for a family of periodic orbits
    with open("x0_diffcorr_fam_eqPt%s_uncoupled.dat" % eqNum,
              'a+') as po_fam_file:
        [po_x0Fam,po_tpFam] = diffcorr.get_po_fam(
            eqNum, Ax1, Ax2, nFam, po_fam_file, uncoupled.init_guess_eqpt_uncoupled, \
            uncoupled.grad_pot_uncoupled, uncoupled.jacobian_uncoupled, \
            uncoupled.guess_lin_uncoupled, uncoupled.diffcorr_setup_uncoupled, \
            uncoupled.conv_coord_uncoupled, uncoupled.diffcorr_acc_corr_uncoupled, \
            uncoupled.ham2dof_uncoupled, uncoupled.half_period_uncoupled, \
            uncoupled.pot_energy_uncoupled, uncoupled.variational_eqns_uncoupled, \
            uncoupled.plot_iter_orbit_uncoupled, parameters)

        poFamRuntime = time.time() - t
        x0podata = np.concatenate((po_x0Fam, po_tpFam), axis=1)

    #%%

    for i in range(len(deltaE_vals)):
        deltaE = deltaE_vals[i]

        with open("x0_diffcorr_fam_eqPt%s_uncoupled.dat" % eqNum,
                  'a+') as po_fam_file:
            eTarget = eSaddle + deltaE
            print('Loading the periodic orbit family from data file',
                  po_fam_file.name, '\n')
            x0podata = np.loadtxt(po_fam_file.name)

        #%
        with open(
                "x0po_T_energyPO_eqPt%s_brac%s_uncoupled.dat" %
            (eqNum, deltaE), 'a+') as po_brac_file:
            t = time.time()

            x0poTarget,TTarget = diffcorr.po_bracket_energy(
                eTarget, x0podata, po_brac_file, \
                uncoupled.diffcorr_setup_uncoupled, uncoupled.conv_coord_uncoupled, \
                uncoupled.diffcorr_acc_corr_uncoupled, uncoupled.ham2dof_uncoupled, \
                uncoupled.half_period_uncoupled, uncoupled.pot_energy_uncoupled, \
                uncoupled.variational_eqns_uncoupled, uncoupled.plot_iter_orbit_uncoupled, \
                parameters)

            poTarE_runtime = time.time() - t
            with open(
                    "model_parameters_eqPt%s_DelE%s_uncoupled.dat" %
                (eqNum, deltaE), 'a+') as model_parameters_file:
                np.savetxt(model_parameters_file.name,
                           parameters,
                           fmt='%1.16e')

        # target specific periodic orbit
        # Target PO of specific energy with high precision does not work for the
        # model

        with open("x0_diffcorr_deltaE%s_uncoupled.dat" % (deltaE),
                  'a+') as po_target_file:

            [x0po, T,energyPO] = diffcorr.po_target_energy(
                x0poTarget,eTarget, po_target_file, \
                uncoupled.diffcorr_setup_uncoupled, uncoupled.conv_coord_uncoupled, \
                uncoupled.diffcorr_acc_corr_uncoupled, \
                uncoupled.ham2dof_uncoupled, uncoupled.half_period_uncoupled, \
                uncoupled.pot_energy_uncoupled, uncoupled.variational_eqns_uncoupled, \
                uncoupled.plot_iter_orbit_uncoupled, parameters)

    #%% Load periodic orbit data from ascii files

    x0po = np.zeros((4, len(deltaE_vals)))

    for i in range(len(deltaE_vals)):
        deltaE = deltaE_vals[i]

        with open("x0_diffcorr_deltaE%s_uncoupled.dat" % (deltaE),
                  'a+') as po_fam_file:
            print('Loading the periodic orbit family from data file',
                  po_fam_file.name, '\n')
            x0podata = np.loadtxt(po_fam_file.name)
        x0po[:, i] = x0podata[0:4]

    #%% Plotting the unstable periodic orbits at the specified energies

    TSPAN = [0, 30]  # arbitrary range, just to finish the integration
    plt.close('all')
    axis_fs = 15
    RelTol = 3.e-10
    AbsTol = 1.e-10

    for i in range(len(deltaE_vals)):
        deltaE = deltaE_vals[i]
        f = lambda t, x: uncoupled.ham2dof_uncoupled(t, x, parameters)
        soln = solve_ivp(f, TSPAN, x0po[:,i],method='RK45',dense_output=True, \
                        events = lambda t,x : uncoupled.half_period_uncoupled(
                            t,x,parameters), \
                        rtol=RelTol, atol=AbsTol)

        te = soln.t_events[0]
        tt = [0, te[1]]
        t,x,phi_t1,PHI = diffcorr.state_transit_matrix(tt, x0po[:,i], parameters, \
                                                uncoupled.variational_eqns_uncoupled)
        ax = plt.gca(projection='3d')
        ax.plot(x[:,0],x[:,1],x[:,3],'-',color = linecolor[i], \
                label = '$\Delta E$ = %.2f'%(deltaE))
        ax.plot(x[:, 0], x[:, 1], -x[:, 3], '-', color=linecolor[i])
        ax.scatter(x[0, 0], x[0, 1], x[0, 3], s=10, marker='*')
        ax.scatter(x[0, 0], x[0, 1], -x[0, 3], s=10, marker='o')
        ax.plot(x[:, 0], x[:, 1], zs=0, zdir='z')

    ax = plt.gca(projection='3d')
    resX = 100
    xVec = np.linspace(-4, 4, resX)
    yVec = np.linspace(-4, 4, resX)
    xMat, yMat = np.meshgrid(xVec, yVec)
    cset1 = ax.contour(
            xMat, yMat, diffcorr.get_pot_surf_proj(
                xVec, yVec, uncoupled.pot_energy_uncoupled, \
                parameters), \
            [0.01,0.1,1,2,4], zdir='z', offset=0, linewidths = 1.0, \
            cmap=cm.viridis, alpha = 0.8)

    ax.scatter(eqPt[0], eqPt[1], s=50, c='r', marker='X')
    ax.set_xlabel('$x$', fontsize=axis_fs)
    ax.set_ylabel('$y$', fontsize=axis_fs)
    ax.set_zlabel('$p_y$', fontsize=axis_fs)

    legend = ax.legend(loc='upper left')
    ax.set_xlim(-4, 4)
    ax.set_ylim(-4, 4)
    ax.set_zlim(-4, 4)

    plt.grid()

    if show_final_plot:
        plt.show()

    if save_final_plot:
        plt.savefig(path_to_saveplot + 'diff_corr_uncoupled_upos.pdf', \
                    format='pdf', bbox_inches='tight')