def update_boundary(eps, delta):
        L = abs(2*np.pi/(kr + delta))

        # choose discretization such that r_nx < len(x_range)
        r_nx_L = (L*(N*pphw + 1)).astype(int)
        x_range = np.linspace(0, L, r_nx_L)

        # no Delta-phase necessary if looking at loop_type constant!
        WG = Dirichlet(loop_type='Constant', N=N, L=L, W=W, eta=eta)

        xi_lower, xi_upper = WG.get_boundary(x=x_range, eps=eps, delta=delta)
        print "lower.boundary.shape", xi_lower.shape

        np.savetxt("lower.boundary", zip(x_range, xi_lower))
        np.savetxt("upper.boundary", zip(x_range, xi_upper))

        N_file_boundary = len(x_range)
        replacements = {'NAME': CALC_NAME,
                        'LENGTH': str(L),
                        'WIDTH': str(W),
                        'MODES': str(N),
                        'PPHW': str(pphw),
                        'GAMMA0': str(eta),
                        'NEUMANN': "0",
                        'N_FILE_BOUNDARY': str(N_file_boundary),
                        'BOUNDARY_UPPER': 'upper.boundary',
                        'BOUNDARY_LOWER': 'lower.boundary'}

        replace_in_file(xml_template, xml, **replacements)
Esempio n. 2
0
def circle_EP(filename=None, write_profile=False, **kwargs):
    """Calculate trajectories around the EP."""

    f = FileOperations(filename)

    WG = Dirichlet(**kwargs)

    ##
    # plot amplitudes b0(x), b1(x)
    ##
    ax0 = plt.subplot2grid((3, 3), (0, 0), colspan=2)
    ax0.set_label("x [a.u.]")
    ax0.set_xlabel(r"x [a.u.]")
    ax0.set_ylabel(r"Amplitudes $|b_n(x)|$")
    set_scientific_axes(ax0)

    x, b0, b1 = WG.solve_ODE()

    # get adiabatic predictions
    b0_ad, b1_ad = (WG.Psi_adiabatic[:, 0], WG.Psi_adiabatic[:, 1])

    # account for initial population of states a and b
    b0_ad *= abs(b0[0])
    b1_ad *= abs(b1[0])

    ax0.semilogy(x, abs(b0), "r-", label=r"$|b_0|$")
    ax0.semilogy(x, abs(b1), "g-", label=r"$|b_1|$")
    ax0.semilogy(x, abs(b0_ad), "b--", label=r"$|b_0^{\mathrm{ad}}|$")
    ax0.semilogy(x, abs(b1_ad), "k--", label=r"$|b_1^{\mathrm{ad}}|$")

    f.write("")
    f.write("Diodicity D = {}".format(abs(b0[-1]) / abs(b1[-1])))
    f.write("Diodicity D^-1 = {}".format(abs(b1[-1]) / abs(b0[-1])))

    plt.rcParams.update({"font.size": 8})

    plt.legend(
        bbox_to_anchor=(0.0, 1.02, 1.0, 0.102),
        loc=3,
        ncol=4,
        mode="expand",
        borderaxespad=0.0,
        labelspacing=0.2,
        columnspacing=0.5,
        handlelength=3,
        handletextpad=0.2,
    )

    ##
    # plot real/imag(E1(t)), imag(E2(t))
    ##
    ax1 = plt.subplot2grid((3, 3), (1, 0), colspan=2)
    ax2 = ax1.twinx()
    set_scientific_axes(ax1, axis="y")
    set_scientific_axes(ax2, axis="y")

    Ea, Eb = WG.eVals[:, 0], WG.eVals[:, 1]

    ax1.set_xlabel("x [a.u.]")
    ax1.set_ylabel("Energy")
    ax1.yaxis.set_label_position("left")
    ax1.plot(x, Ea.imag, "r-", label=r"$\mathrm{Im}(E_0)$")
    ax1.plot(x, Eb.imag, "g-", label=r"$\mathrm{Im}(E_1)$")
    ax2.plot(x, Ea.real, "r--", label=r"$\mathrm{Re}(E_0)$")
    ax2.plot(x, Eb.real, "g--", label=r"$\mathrm{Re}(E_1)$")

    t_imag = map_trajectory(b0, b1, Ea.imag, Eb.imag)
    t_real = map_trajectory(b0, b1, Ea.real, Eb.real)
    ax1.plot(x, t_imag, "k-")
    ax2.plot(x, t_real, "k--")

    lines1, labels1 = ax1.get_legend_handles_labels()
    lines2, labels2 = ax2.get_legend_handles_labels()
    ax2.legend(
        lines1 + lines2,
        labels1 + labels2,
        bbox_to_anchor=(0.0, 1.02, 1.0, 0.102),
        loc=3,
        ncol=4,
        mode="expand",
        borderaxespad=0.0,
        labelspacing=0.2,
        columnspacing=0.5,
        handlelength=2.5,
        handletextpad=0.2,
    )

    ##
    # plot wavefunction
    ##
    x0, y0 = WG.get_cycle_parameters(0.0)
    x1, y1 = WG.get_cycle_parameters(WG.t)
    ####
    ####ax3 = subplot2grid((3,3), (2,0), colspan=2)
    ####WG.draw_wavefunction()
    ####WG.draw_dissipation_coefficient()
    ####WG.draw_boundary()
    ####tick_params(labelleft='off', left='off', right='off')
    ####ax3.set_xlabel("x [a.u.]")
    ####ax3.set_frame_on(False)
    # ax3.xaxis.set_ticklabels([])
    # ax3.get_xaxis().tick_bottom()

    ##
    # plot path around EP
    ##
    ax4 = plt.subplot2grid((3, 3), (2, 0))
    set_scientific_axes(ax4, axis="both")
    ax4.xaxis.set_label_position("top")
    ax4.yaxis.set_label_position("right")
    plt.xticks(rotation=30)

    ax4.set_xlabel(r"$\epsilon$", fontsize=10)
    ax4.set_ylabel(r"$\delta$", fontsize=10)
    dx = dy = 0.5e-2
    # ax4.set_xlim(min(x1)-dx, max(x1)+dx)
    # ax4.set_ylim(min(y1)-dy, max(y1)+dy)

    offset = WG.tN / 5.0
    dx1 = np.diff(x1)
    dy1 = np.diff(y1)
    plt.plot(x1[:], y1[:], "grey", ls="dotted")
    plt.plot(x0, y0, "ro", mew=0.0, mec="r")
    plt.plot([WG.x_EP, -WG.x_EP], [WG.y_EP, WG.y_EP], "ko")

    plt.quiver(
        x1[offset:-1:offset],
        y1[offset:-1:offset],
        dx1[offset::offset],
        dy1[offset::offset],
        units="xy",
        angles="xy",
        headwidth=6.0,
        color="k",
        zorder=10,
    )
    # ylim(-0.1,0.1)
    # text(WG.x_EP - WG.x_R0*0.2,
    #     WG.y_EP + WG.y_R0*4, "EP")

    ##
    # save figure
    ##
    # tight_layout()
    plt.subplots_adjust(  # left=0.125,
        bottom=None,
        # right=0.9,
        top=None,
        wspace=0.5,
        hspace=0.6,
    )

    filename = "{0}_{1}".format(filename, kwargs.get("loop_direction"))
    f.write(filename + ".cfg")
    # plt.savefig(filename + ".pdf")
    plt.savefig(filename + ".png")
    if write_profile:
        xi_lower, _ = WG.get_boundary()
        np.savetxt(filename + ".profile", zip(WG.t, xi_lower))
    plt.clf()