def overlap_func(theta, i, j, params):
    q = -params.Ej / (2 * params.Ec)
    if i % 2 == 0:
        bra = np.conjugate(special.mathieu_cem(
            i, q, theta * 180 / np.pi)[0]) * np.sqrt(2 / np.pi)
    else:
        bra = np.conjugate(
            special.mathieu_sem(i + 1, q, theta * 180 / np.pi)[0]) * np.sqrt(
                2 / np.pi)
    if j % 2 == 0:
        ket = special.mathieu_cem(j, q, theta * 180 / np.pi)[1] * np.sqrt(
            2 / np.pi)
    else:
        ket = special.mathieu_sem(j + 1, q, theta * 180 / np.pi)[1] * np.sqrt(
            2 / np.pi)
    overlap_point = bra * ket

    return overlap_point
Пример #2
0
def test_mathiue_dgl(plot=False):
    t0 = 0
    tmax = 2*np.pi
    N = 401
    m = 3
    q = 5

    t1 = time.time()    
    res = solve_mathiue_dgl(t0, tmax, N, m, q)
    t = res[0,:]
    
    t2 = time.time()
    
    print((t2-t1)*500)
    
    y, yp = mathieu_cem(m, q, t*360/2/np.pi)
    
    
    rel_diff_y = np.abs(y - res[1,:])/np.abs(y)
    idx_sel = np.where(yp != 0)[0] 
    
    rel_diff_yp = np.abs(yp[idx_sel] - res[2,idx_sel])/np.abs(yp[idx_sel])
    
    assert np.max(rel_diff_y < 1e-4)
    assert np.max(rel_diff_yp < 1e-4)
    
    if plot:
    
        fig, ax = plt.subplots(nrows=2, ncols=1, sharex=True)
        
        ax[0].plot(t, y, c='k')
        ax[0].plot(t, res[1], c='r')
        ax[0].plot(t, yp, c='k')
        ax[0].plot(t, res[2], c='r')
        ax[0].grid()
        
        ax[1].plot(t, rel_diff_y)
        ax[1].plot(t[idx_sel], rel_diff_yp)
        
        ax[1].set_yscale('log')
        ax[1].grid()
        
        plt.show()
Пример #3
0
def solve_mathiue_dgl(t0, tmax, N, m, q):
    a = mathieu_a(m, q)
    y0 = mathieu_cem(m, q, 0)
    
    t = np.linspace(t0, tmax, N, endpoint=True)
    res = np.empty(shape=(3,N))
    res[0,0] = t[0]
    res[1,0], res[2,0] = y0
    
    r = ode(dgl_mathieu)
    r.set_integrator('lsoda', atol=1e-10, rtol=1e-10)
    r.set_initial_value(y=y0, t=t0)
    r.set_f_params(a, q)
     
    for i in range(1, N):
        r.integrate(t[i])
        res[0,i] = r.t
        res[1,i], res[2,i] = r.y
    return res
Пример #4
0
    def _mathieu_function(self, s, theta):
        """
        Returns Mathieu function evaluated at angle `theta' for biasing
        parameter `s'.

        Notation from https://en.wikipedia.org/wiki/Mathieu_function.

        Parameters
        ----------
        s : float
            Biasing parameter.
        theta : float
            Angle (in radians) at which to evaluate.

        Returns
        -------
        ce : float
            Mathieu function evaluated at `theta'.
        """

        return special.mathieu_cem(self._mathieu_order,
                                   self._mathieu_characteristic_q(s),
                                   (180. / np.pi) * theta / 2.)[0]
Пример #5
0
def mathieu_ce_rad(m, q, x):
    return mathieu_cem(m, q, x*180/np.pi)[0]
Пример #6
0
def mathieu_ce_rad(m, q, x):
    return mathieu_cem(m, q, x*180/np.pi)[0]
Пример #7
0
def actfc(m, q, z):
    #z=degrad(z)
    return (sp.mathieu_cem(m, q, z)[0], sp.mathieu_sem(m, q, z)[0])
Пример #8
0
def test_distributed_mathieu():
    q_min = 0
    q_max = 15
    q_N = 50
    m = 3
    
    t0 = 0
    t1 = 2*np.pi
    
    N = q_N
    
    # t0, t1, N, f, args, x0, integrator, verbose
    const_arg = jm.hashDict()
    const_arg['t0'] = t0
    const_arg['t1'] = t1
    const_arg['N'] = N
    const_arg['f'] = dgl_mathieu
    const_arg['integrator'] = 'vode'
    const_arg['atol'] = 1e-10
    const_arg['rtol'] = 1e-10
    const_arg['verbose'] = 0
    
    authkey = 'integration_jm'
    
    with jm.JobManager_Local(client_class = jm.clients.Integration_Client_REAL,
                             authkey = authkey,
                             port = 42525,
                             const_arg = const_arg,
                             nproc=1,
                             verbose_client=2,
                             niceness_clients=0,
                             show_statusbar_for_jobs=False) as jm_int:
        q_list = np.linspace(q_min, q_max, q_N)
        for q in q_list:
            arg = jm.hashDict()
            a = mathieu_a(m, q)
            arg['args'] = (a, q)
            arg['x0'] = mathieu_cem(m, q, 0) # gives value and its derivative
            jm_int.put_arg(a=arg)        
        
        jm_int.start()
        
    data = np.empty(shape=(3, q_N*N), dtype=np.float64)
    
    t_ref = np.linspace(t0, t1, N)
    
    tot_time = 0
    
    max_diff_x = 0
    max_diff_x_dot = 0
    
        
    for i, f in enumerate(jm_int.final_result):
        arg = f[0]
        res = f[1]
        
        a, q = arg['args']
        t, x_t = f[1]
        
        assert np.max(np.abs(t_ref - t)) < 1e-15
        time1 = time.time()
        res = solve_mathiue_dgl(t0, t1, N, m, q)
        time2 = time.time()
        tot_time += (time2 - time1)
        
        max_diff_x = max(max_diff_x, np.max(np.abs(x_t[:,0] - res[1,:])))
        max_diff_x_dot = max(max_diff_x_dot, np.max(np.abs(x_t[:,1] - res[2,:])))        
        
        data[0, i*q_N: (i+1)*q_N] = t
        data[1, i*q_N: (i+1)*q_N] = q
        data[2, i*q_N: (i+1)*q_N] = np.real(x_t[:,0])

    assert max_diff_x < 1e-6, max_diff_x       
    assert max_diff_x_dot < 1e-6, max_diff_x_dot 
    print("time normal integration:", tot_time)
Пример #9
0
from numpy import *
from scipy.special import mathieu_cem
import matplotlib.pyplot as plt
from matplotlib import cm
from scipy.integrate import quad

## parameters ##
i = 1.0j
x = linspace(-pi, pi, 200)
p = linspace(-5, 5, 200)
x, p = meshgrid(x, p)
y = linspace(-pi, pi, 200)

psi = (mathieu_cem(0, -1, (x - y / 2) * 180 / pi)[0])
psic = transpose(conj(mathieu_cem(0, -1, (x + y / 2) * 180 / pi)[0]))


## defining the integral ##
def integrand(y, x, p):
    return psic * psi * exp(2 * i * p * y)


## generating Wigner function ##
def W(x, p):
    return quad(integrand, -pi, pi, args=(x, p))[0]


W = vectorize(W)
# Plot the figure
fig, axes = plt.subplots()
from numpy import *
from scipy.special import mathieu_sem, mathieu_cem
import matplotlib.pyplot as plt
from matplotlib import cm

i = 1.0j

for zeta in range(-2, 2):

    x = linspace(-pi, pi, 200)
    p = linspace(-5, 5, 200)
    x, p = meshgrid(x, p)

    psi = (mathieu_cem(0, -1, (x - (zeta / 2)) * 180 / pi)[0])
    psic = transpose(conj(mathieu_cem(0, -1, (x + (zeta / 2)) * 180 / pi)[0]))
    W = (psic * psi * exp(2 * i * p * zeta)) / 3

# Plot the figure
fig, axes = plt.subplots(figsize=(8, 6))
# Make room for the x-axis label which would get clipped otherwise
fig.subplots_adjust(bottom=0.15)

# Contours and filled contours
cv = axes.contour(x, p, W, color='k')
cont = axes.contourf(x, p, W, 1000, cmap=cm.jet)

# Axis ticks and labels
axes.set_xlabel(r'x')
axes.set_ylabel(r'p', labelpad=-10)
cb = fig.colorbar(cont, ax=axes)  # add colour bar
plt.title('Ce(order=0, q=-1, x)')