Example #1
0
def residual(x,U,dU):

	ux_r = U[0:ct.nz]
	ux_i = U[ct.nz:2*ct.nz]
	b_par_r = U[2*ct.nz:3*ct.nz]
	b_par_i = U[3*ct.nz:4*ct.nz]
	u_perp_r = U[4*ct.nz:5*ct.nz]
	u_perp_i = U[5*ct.nz:]

	dux_r = dU[0:ct.nz]
	dux_i = dU[ct.nz:2*ct.nz]
	db_par_r = dU[2*ct.nz:3*ct.nz]
	db_par_i = dU[3*ct.nz:4*ct.nz]
	du_perp_r = dU[4*ct.nz:5*ct.nz]
	du_perp_i = dU[5*ct.nz:]

	ux = ux_r + 1j * ux_i
	b_par = b_par_r + 1j * b_par_i
	u_perp = u_perp_r + 1j * u_perp_i

	dux = dux_r + 1j * dux_i
	db_par = db_par_r + 1j * db_par_i
	du_perp = du_perp_r + 1j * du_perp_i

	nabla_perp_b_par  = 1j * ct.k_perp * b_par  - np.sin(ct.alpha) * psdiff(b_par, period = 2 * ct.Lz)
	nabla_perp_u_perp = 1j * ct.k_perp * u_perp - np.sin(ct.alpha) * psdiff(u_perp, period = 2 * ct.Lz)
	L_ux     = np.cos(ct.alpha) ** 2 * psdiff(ux, order = 2, period = 2 * ct.Lz) \
			    + ct.omega ** 2 / ct.vA(x,ct.z) ** 2 * ux
	L_u_perp = np.cos(ct.alpha) ** 2 * psdiff(u_perp, order = 2, period = 2 * ct.Lz) \
				+ ct.omega ** 2 / ct.vA(x,ct.z) ** 2 * u_perp

	# nabla_perp_b_par  = 1j * ct.k_perp * b_par  - 1j * np.sin(ct.alpha) * b_par
	# nabla_perp_u_perp = 1j * ct.k_perp * u_perp - 1j * np.sin(ct.alpha) * u_perp
	# L_ux     = -ct.kz ** 2 * np.cos(ct.alpha) ** 2 * ux \
	# 		    + ct.omega ** 2 / ct.vA(x,ct.z) ** 2 * ux
	# L_u_perp = -ct.kz ** 2 * np.cos(ct.alpha) ** 2 * u_perp \
	# 			+ ct.omega ** 2 / ct.vA(x,ct.z) ** 2 * u_perp

	res = np.zeros(6 * ct.nz)
	res[0:ct.nz]         = np.real(dux + 1j * ct.omega * b_par + nabla_perp_u_perp)
	res[ct.nz:2*ct.nz]   = np.imag(dux + 1j * ct.omega * b_par + nabla_perp_u_perp)
	res[2*ct.nz:3*ct.nz] = np.real(db_par + 1j / ct.omega * L_ux)
	res[3*ct.nz:4*ct.nz] = np.imag(db_par + 1j / ct.omega * L_ux)
	res[4*ct.nz:5*ct.nz] = np.real(L_u_perp - 1j * ct.omega * nabla_perp_b_par)
	res[5*ct.nz:]        = np.imag(L_u_perp - 1j * ct.omega * nabla_perp_b_par)

	return res
Example #2
0
def dUdx(x, U):
    ux = U[0:ct.nz]
    b_par = U[ct.nz:]
    u_perp = td.calc_u_perp(x, b_par)

    dux_dx = -(1j * ct.omega * b_par + 1j * ct.k_perp * u_perp - \
       np.sin(ct.alpha) / (2 * ct.dz) * (np.roll(u_perp,-1) - np.roll(u_perp,1)))
    db_par_dx = -1j / ct.omega * ( \
       np.cos(ct.alpha) ** 2 / ct.dz ** 2 * (np.roll(ux,-1) - 2 * ux  + np.roll(ux,1))  + \
       ct.omega ** 2 / ct.vA(x,ct.z) ** 2 * ux)
    return np.concatenate((dux_dx, db_par_dx))
Example #3
0
def plot_vA(ix0, iz0):
    fig = plt.figure()
    fig_size = fig.get_size_inches()
    fig_size[0] = 3 * fig_size[0]
    fig.set_size_inches(fig_size)

    ax = fig.add_subplot(131)
    ax.plot(ct.z, ct.vA(ct.x[ix0], ct.z))
    ax.set_xlabel('z')
    ax.set_title(r'$v_A(z)$' + r' at $x = $' + "{:.2f}".format(ct.x[ix0]))

    ax = fig.add_subplot(132)
    ax.plot(ct.x / abs(ct.xi), ct.vA(ct.x, ct.z[iz0]))
    ax.set_xlabel(r'$x / |x_i|$')
    ax.set_title(r'$v_A(x)$' + r' at $z = $' + "{:.2f}".format(ct.z[iz0]))

    ax = fig.add_subplot(133, projection='3d')
    surf = ax.plot_surface(ct.X, ct.Z, ct.vA(ct.X, ct.Z), cmap=cm.cool)
    ax.set_xlabel(r'$x / |x_i|$')
    ax.set_ylabel(r'$z$')
    ax.set_title(r'$v_A(x,z)$')
    fig.savefig('Figures/vA.png', bbox_inches='tight')
Example #4
0
def calc_A_u_v(x):

	a = np.full(ct.nz, np.cos(ct.alpha) ** 2 / ct.dz ** 2, dtype=complex) # Off diagonal elements
	b = -2 * a + ct.omega ** 2 / ct.vA(x,ct.z) ** 2                       # Diagonal elements
	b0 = b[0]
	b[0]  += b0
	b[-1] += a[0] ** 2 / b0

	ab = np.zeros((3, ct.nz), dtype=complex)
	ab[0,:] = a
	ab[1,:] = b
	ab[2,:] = a

	u = np.zeros(ct.nz, dtype=complex)
	v = np.zeros(ct.nz, dtype=complex)
	u[0] = -b0
	u[-1] = a[0]
	v[0] = 1
	v[-1] = -a[0] / b0

	return [ab, u, v]