예제 #1
0
def test_lower_hybrid_frequency():
    r"""Test the lower_hybrid_frequency function in parameters.py."""

    ion = 'He-4 1+'
    omega_ci = gyrofrequency(B, particle=ion)
    omega_pi = plasma_frequency(n=n_i, particle=ion)
    omega_ce = gyrofrequency(B)
    omega_lh = lower_hybrid_frequency(B, n_i=n_i, ion=ion)
    assert omega_ci.unit.is_equivalent(u.rad / u.s)
    assert omega_pi.unit.is_equivalent(u.rad / u.s)
    assert omega_ce.unit.is_equivalent(u.rad / u.s)
    assert omega_lh.unit.is_equivalent(u.rad / u.s)
    left_hand_side = omega_lh**-2
    right_hand_side = 1 / (omega_ci**2 +
                           omega_pi**2) + omega_ci**-1 * omega_ce**-1
    assert np.isclose(left_hand_side.value, right_hand_side.value)

    with pytest.raises(ValueError):
        lower_hybrid_frequency(0.2 * u.T, n_i=5e19 * u.m**-3, ion='asdfasd')

    with pytest.raises(ValueError):
        lower_hybrid_frequency(0.2 * u.T, n_i=-5e19 * u.m**-3, ion='asdfasd')

    with pytest.raises(ValueError):
        lower_hybrid_frequency(np.nan * u.T,
                               n_i=-5e19 * u.m**-3,
                               ion='asdfasd')

    with pytest.warns(u.UnitsWarning):
        assert lower_hybrid_frequency(1.3, 1e19) == lower_hybrid_frequency(
            1.3 * u.T, 1e19 * u.m**-3)
    assert_can_handle_nparray(lower_hybrid_frequency)
예제 #2
0
def cold_plasma_LRP(B, species, n, omega ,flag= True ):
    """

    @param B: Magnetic field in z direction
    @param species: ['e','p'] means electrons and protons
    @param n: The density of different species
    @param omega: wave_frequency
    @param flag: if flag == 1 then omega means to be a number, if flag is not True the omega means a symbol
    @return: (l, R, P)

    """

    if flag:
        wave_frequency = omega
        w = wave_frequency.value
    else:
        wave_frequency = symbols('w')
        w = wave_frequency
    L, R, P = 1, 1, 1

    for s, n_s in zip(species, n):
        omega_c = parameters.gyrofrequency(B=B, particle=s, signed=True)
        omega_p = parameters.plasma_frequency(n=n_s, particle=s)

        L += - omega_p.value ** 2 / (w * (w - omega_c.value))
        R += - omega_p.value ** 2 / (w * (w + omega_c.value))
        P += - omega_p.value ** 2 / w ** 2
    return L, R, P
예제 #3
0
def test_upper_hybrid_frequency():
    r"""Test the upper_hybrid_frequency function in parameters.py."""

    omega_uh = upper_hybrid_frequency(B, n_e=n_e)
    omega_ce = gyrofrequency(B)
    omega_pe = plasma_frequency(n=n_e)
    assert omega_ce.unit.is_equivalent(u.rad / u.s)
    assert omega_pe.unit.is_equivalent(u.rad / u.s)
    assert omega_uh.unit.is_equivalent(u.rad / u.s)
    left_hand_side = omega_uh**2
    right_hand_side = omega_ce**2 + omega_pe**2
    assert np.isclose(left_hand_side.value, right_hand_side.value)

    with pytest.raises(ValueError):
        upper_hybrid_frequency(5 * u.T, n_e=-1 * u.m**-3)

    with pytest.warns(u.UnitsWarning):
        assert upper_hybrid_frequency(1.2, 1.3) == upper_hybrid_frequency(
            1.2 * u.T, 1.3 * u.m**-3)

    with pytest.warns(u.UnitsWarning):
        assert upper_hybrid_frequency(1.4 * u.T,
                                      1.3) == upper_hybrid_frequency(
                                          1.4, 1.3 * u.m**-3)

    assert_can_handle_nparray(upper_hybrid_frequency)
예제 #4
0
 def __init__(self, name, density, magnetic_field, Tx, Tz):
     self.name = name
     self.density = density
     self.gyro_f = parameters.gyrofrequency(B=magnetic_field,
                                            particle=name,
                                            signed=True)
     self.plasma_f = parameters.plasma_frequency(density, particle=name)
     self.Tx = Tx
     self.Tz = Tz
     self.vth_x = parameters.thermal_speed(Tx * u.K, name).value
     self.vth_z = parameters.thermal_speed(Tz * u.K, name).value
예제 #5
0
def anisotropy(name, density, B, T_perp, T_para, waveperOmega, distribution):
    if name == 'e':
        n = density[0]
    else:
        n = density[1]

    electron = particle.particles(name, n, B, T_perp, T_para)
    species = ['e', 'p']
    theta_input = 0
    theta_deg = theta_input * pi / 180
    vx = symbols('vx')
    vz = symbols('vz')
    vth_x = symbols('vth_x')
    vth_z = symbols('vth_z')
    G1_term1, G1_term2 = electron.G_1(distribution)
    if distribution == 'drift':
        f = electron.F_1()
    else:
        f = electron.F_0()

    gyro_frequency = parameters.gyrofrequency(B, name)
    wave_frequency = waveperOmega * gyro_frequency

    refraction_index_para = disper.solve_dispersion(B, species, density,
                                                    wave_frequency,
                                                    theta_input)

    # result_x = integrate(f, (vz, -oo, oo))
    # result = integrate(2 * pi * vx * result_x, (vx, 0, oo))

    # set w and Omega and k
    Omega = gyro_frequency.value
    w = wave_frequency.value

    c = const.c.value
    k = refraction_index_para * w / c
    k_para = k * cos(theta_deg)
    k_para_c = k_para * c

    vz_res = (w - Omega) / (k_para)
    A_bottom = 2 * integrate(f * vx, (vx, 0, oo))
    A_top = vz**-1 * integrate(vx**2 * G1_term2, (vx, 0, oo))
    A_res = simplify((A_top / A_bottom).subs(vz, vz_res))
    A_res_value = A_res.subs([(vth_x, electron.vth_x),
                              (vth_z, electron.vth_z)])
    Eta_res = 2 * pi * (-vz) * integrate(vx * f, (vx, 0, oo))
    Eta_res_v = Eta_res.subs(vz, vz_res)
    Eta_res_value = Eta_res_v.subs([(vth_x, electron.vth_x),
                                    (vth_z, electron.vth_z)])
    A_c = 1 / ((Omega - w) - 1)
    wave_growth = pi * Omega * (1 - w / Omega)**2 * Eta_res_value * (
        A_res_value - A_c)
    return A_res_value, Eta_res_value, wave_growth.evalf()
예제 #6
0
def test_gyroradius():
    r"""Test the gyroradius function in parameters.py."""

    assert gyroradius(B, T_i=T_e).unit.is_equivalent(u.m)

    assert gyroradius(B, Vperp=25 * u.m / u.s).unit.is_equivalent(u.m)

    Vperp = 1e6 * u.m / u.s
    Bmag = 1 * u.T
    omega_ce = gyrofrequency(Bmag)
    analytical_result = (Vperp / omega_ce).to(
        u.m, equivalencies=u.dimensionless_angles())
    assert gyroradius(Bmag, Vperp=Vperp) == analytical_result

    with pytest.raises(TypeError):
        gyroradius(u.T)

    with pytest.raises(u.UnitConversionError):
        gyroradius(5 * u.A, Vperp=8 * u.m / u.s)

    with pytest.raises(u.UnitConversionError):
        gyroradius(5 * u.T, Vperp=8 * u.m)

    with pytest.raises(ValueError):
        gyroradius(np.array([5, 6]) * u.T,
                   Vperp=np.array([5, 6, 7]) * u.m / u.s)

    with pytest.raises(ValueError):
        gyroradius(np.nan * u.T, Vperp=1 * u.m / u.s)

    with pytest.raises(ValueError):
        gyroradius(3.14159 * u.T, T_i=-1 * u.K)

    with pytest.warns(u.UnitsWarning):
        assert gyroradius(1.0, Vperp=1.0) == gyroradius(1.0 * u.T,
                                                        Vperp=1.0 * u.m / u.s)

    with pytest.warns(u.UnitsWarning):
        assert gyroradius(1.1, T_i=1.2) == gyroradius(1.1 * u.T, T_i=1.2 * u.K)

    with pytest.raises(ValueError):
        gyroradius(1.1 * u.T, Vperp=1 * u.m / u.s, T_i=1.2 * u.K)

    with pytest.raises(ValueError):
        gyroradius(1.1 * u.T, Vperp=1.1 * u.m, T_i=1.2 * u.K)

    assert gyroradius(B, particle="p", T_i=T_i).unit.is_equivalent(u.m)

    assert gyroradius(B, particle="p",
                      Vperp=25 * u.m / u.s).unit.is_equivalent(u.m)

    # Case when Z=1 is assumed
    assert np.isclose(gyroradius(B, particle='p', T_i=T_i),
                      gyroradius(B, particle='H+', T_i=T_i),
                      atol=1e-6 * u.m)

    gyroPos = gyroradius(B, particle="p", Vperp=V)
    gyroNeg = gyroradius(B, particle="p", Vperp=-V)
    assert gyroPos == gyroNeg

    Vperp = 1e6 * u.m / u.s
    Bmag = 1 * u.T
    omega_ci = gyrofrequency(Bmag, particle='p')
    analytical_result = (Vperp / omega_ci).to(
        u.m, equivalencies=u.dimensionless_angles())
    assert gyroradius(Bmag, particle="p", Vperp=Vperp) == analytical_result

    T2 = 1.2 * u.MK
    B2 = 123 * u.G
    particle2 = 'alpha'
    Vperp2 = thermal_speed(T2, particle=particle2)
    gyro_by_vperp = gyroradius(B2, particle='alpha', Vperp=Vperp2)
    assert gyro_by_vperp == gyroradius(B2, particle='alpha', T_i=T2)

    explicit_positron_gyro = gyroradius(1 * u.T,
                                        particle='positron',
                                        T_i=1 * u.MK)
    assert explicit_positron_gyro == gyroradius(1 * u.T, T_i=1 * u.MK)

    with pytest.raises(TypeError):
        gyroradius(u.T, particle="p", Vperp=8 * u.m / u.s)

    with pytest.raises(ValueError):
        gyroradius(B, particle='p', T_i=-1 * u.K)

    with pytest.warns(u.UnitsWarning):
        gyro_without_units = gyroradius(1.0, particle="p", Vperp=1.0)
        gyro_with_units = gyroradius(1.0 * u.T,
                                     particle="p",
                                     Vperp=1.0 * u.m / u.s)
        assert gyro_without_units == gyro_with_units

    with pytest.warns(u.UnitsWarning):
        gyro_t_without_units = gyroradius(1.1, particle="p", T_i=1.2)
        gyro_t_with_units = gyroradius(1.1 * u.T, particle="p", T_i=1.2 * u.K)
        assert gyro_t_with_units == gyro_t_without_units

    with pytest.raises(ValueError):
        gyroradius(1.1 * u.T, particle="p", Vperp=1 * u.m / u.s, T_i=1.2 * u.K)

    with pytest.raises(ValueError):
        gyroradius(1.1 * u.T, particle="p", Vperp=1.1 * u.m, T_i=1.2 * u.K)

    with pytest.raises(ValueError):
        gyroradius(1.1 * u.T, particle="p", Vperp=1.2 * u.m, T_i=1.1 * u.K)
예제 #7
0
def test_gyrofrequency():
    r"""Test the gyrofrequency function in parameters.py."""

    assert gyrofrequency(B).unit.is_equivalent(u.rad / u.s)

    assert np.isclose(gyrofrequency(1 * u.T).value, 175882008784.72018)

    assert np.isclose(gyrofrequency(2.4 * u.T).value, 422116821083.3284)

    assert np.isclose(
        gyrofrequency(2.4 * u.T, signed=True).value, -422116821083.3284)

    assert np.isclose(gyrofrequency(1 * u.G).cgs.value, 1.76e7, rtol=1e-3)

    with pytest.raises(TypeError):
        gyrofrequency(u.m)

    with pytest.raises(u.UnitConversionError):
        gyrofrequency(u.m * 1)

    with pytest.raises(ValueError):
        gyrofrequency(B_nanarr)

    # The following is a test to check that equivalencies from astropy
    # are working.
    omega_ce = gyrofrequency(2.2 * u.T)
    f_ce = (omega_ce / (2 * np.pi)) / u.rad
    f_ce_use_equiv = omega_ce.to(u.Hz, equivalencies=[(u.cy / u.s, u.Hz)])
    assert np.isclose(f_ce.value, f_ce_use_equiv.value)

    with pytest.warns(u.UnitsWarning):
        assert gyrofrequency(5.0) == gyrofrequency(5.0 * u.T)

    assert gyrofrequency(B, particle=ion).unit.is_equivalent(u.rad / u.s)

    assert np.isclose(
        gyrofrequency(1 * u.T, particle='p').value, 95788335.834874)

    assert np.isclose(
        gyrofrequency(2.4 * u.T, particle='p').value, 229892006.00369796)

    assert np.isclose(gyrofrequency(1 * u.G, particle='p').cgs.value,
                      9.58e3,
                      rtol=2e-3)

    assert gyrofrequency(-5 * u.T, 'p') == gyrofrequency(5 * u.T, 'p')

    # Case when Z=1 is assumed
    # assert gyrofrequency(B, particle='p+') == gyrofrequency(B, particle='H-1')

    assert gyrofrequency(B, particle='e+') == gyrofrequency(B)

    with pytest.warns(u.UnitsWarning):
        gyrofrequency(8, 'p')

    with pytest.raises(u.UnitConversionError):
        gyrofrequency(5 * u.m, 'p')

    with pytest.raises(InvalidParticleError):
        gyrofrequency(8 * u.T, particle='asdfasd')

    with pytest.warns(u.UnitsWarning):
        # TODO this should be WARNS, not RAISES. and it's probably still raised
        assert gyrofrequency(5.0, 'p') == gyrofrequency(5.0 * u.T, 'p')

    gyrofrequency(1 * u.T, particle='p')
    # testing for user input Z
    testMeth1 = gyrofrequency(1 * u.T, particle='p', Z=0.8).si.value
    testTrue1 = 76630665.79318453
    errStr = f"gyrofrequency() gave {testMeth1}, should be {testTrue1}."
    assert np.isclose(testMeth1, testTrue1, atol=0.0, rtol=1e-15), errStr

    assert_can_handle_nparray(gyrofrequency, kwargs={"signed": True})

    assert_can_handle_nparray(gyrofrequency, kwargs={"signed": False})
예제 #8
0
 def time_gyrofrequency(self):
     gyrofrequency(0.01*u.T,
                   particle='T+',
                   to_hz=True)
예제 #9
0
def cold_plasma_permittivity_SDP(B, species, n, omega):
    r"""
    Magnetized Cold Plasma Dielectric Permittivity Tensor Elements.

    Elements (S, D, P) are given in the "Stix" frame, ie. with B // z.

    The :math:`\exp(-i \omega t)` time-harmonic convention is assumed.

    Parameters
    ----------
    B : ~astropy.units.Quantity
        Magnetic field magnitude in units convertible to tesla.

    species : list of str
        List of the plasma particle species
        e.g.: ['e', 'D+'] or ['e', 'D+', 'He+'].

    n : list of ~astropy.units.Quantity
        `list` of species density in units convertible to per cubic meter
        The order of the species densities should follow species.

    omega : ~astropy.units.Quantity
        Electromagnetic wave frequency in rad/s.

    Returns
    -------
    S : ~astropy.units.Quantity
        S ("Sum") dielectric tensor element.

    D : ~astropy.units.Quantity
        D ("Difference") dielectric tensor element.

    P : ~astropy.units.Quantity
        P ("Plasma") dielectric tensor element.

    Notes
    -----
    The dielectric permittivity tensor is expressed in the Stix frame with
    the :math:`\exp(-i \omega t)` time-harmonic convention as
    :math:`\varepsilon = \varepsilon_0 A`, with :math:`A` being

    .. math::

        \varepsilon = \varepsilon_0 \left(\begin{matrix}  S & -i D & 0 \\
                              +i D & S & 0 \\
                              0 & 0 & P \end{matrix}\right)

    where:

    .. math::
        S = 1 - \sum_s \frac{\omega_{p,s}^2}{\omega^2 - \Omega_{c,s}^2}

        D = \sum_s \frac{\Omega_{c,s}}{\omega}
            \frac{\omega_{p,s}^2}{\omega^2 - \Omega_{c,s}^2}

        P = 1 - \sum_s \frac{\omega_{p,s}^2}{\omega^2}

    where :math:`\omega_{p,s}` is the plasma frequency and
    :math:`\Omega_{c,s}` is the signed version of the cyclotron frequency
    for the species :math:`s`.

    References
    ----------
    - T.H. Stix, Waves in Plasma, 1992.

    Examples
    --------
    >>> from astropy import units as u
    >>> from plasmapy.constants import pi
    >>> B = 2*u.T
    >>> species = ['e', 'D+']
    >>> n = [1e18*u.m**-3, 1e18*u.m**-3]
    >>> omega = 3.7e9*(2*pi)*(u.rad/u.s)
    >>> S, D, P = cold_plasma_permittivity_SDP(B, species, n, omega)
    >>> S
    <Quantity 1.02422902>
    >>> D
    <Quantity 0.39089352>
    >>> P
    <Quantity -4.8903104>
    """
    S, D, P = 1, 0, 1

    for s, n_s in zip(species, n):
        omega_c = parameters.gyrofrequency(B=B, particle=s, signed=True)
        omega_p = parameters.plasma_frequency(n=n_s, particle=s)

        S += -omega_p**2 / (omega**2 - omega_c**2)
        D += omega_c / omega * omega_p**2 / (omega**2 - omega_c**2)
        P += -omega_p**2 / omega**2
    return S, D, P
예제 #10
0
def cold_plasma_permittivity_LRP(B: u.T, species, n, omega: u.rad / u.s):
    r"""
    Magnetized Cold Plasma Dielectric Permittivity Tensor Elements.

    Elements (L, R, P) are given in the "rotating" basis, ie. in the basis
    :math:`(\mathbf{u}_{+}, \mathbf{u}_{-}, \mathbf{u}_z)`,
    where the tensor is diagonal and with B // z.

    The :math:`\exp(-i \omega t)` time-harmonic convention is assumed.

    Parameters
    ----------
    B : ~astropy.units.Quantity
        Magnetic field magnitude in units convertible to tesla.

    species : list of str
        The plasma particle species (e.g.: `['e', 'D+']` or
        `['e', 'D+', 'He+']`.

    n : list of ~astropy.units.Quantity
        `list` of species density in units convertible to per cubic meter.
        The order of the species densities should follow species.

    omega : ~astropy.units.Quantity
        Electromagnetic wave frequency in rad/s.

    Returns
    -------
    L : ~astropy.units.Quantity
        L ("Left") Left-handed circularly polarization tensor element.

    R : ~astropy.units.Quantity
        R ("Right") Right-handed circularly polarization tensor element.

    P : ~astropy.units.Quantity
        P ("Plasma") dielectric tensor element.

    Notes
    -----
    In the rotating frame defined by
    :math:`(\mathbf{u}_{+}, \mathbf{u}_{-}, \mathbf{u}_z)`
    with :math:`\mathbf{u}_{\pm}=(\mathbf{u}_x \pm \mathbf{u}_y)/\sqrt{2}`,
    the dielectric tensor takes a diagonal form with elements L, R, P with:

    .. math::
        L = 1 - \sum_s
                \frac{\omega_{p,s}^2}{\omega\left(\omega - \Omega_{c,s}\right)}

        R = 1 - \sum_s
                \frac{\omega_{p,s}^2}{\omega\left(\omega + \Omega_{c,s}\right)}

        P = 1 - \sum_s \frac{\omega_{p,s}^2}{\omega^2}

    where :math:`\omega_{p,s}` is the plasma frequency and
    :math:`\Omega_{c,s}` is the signed version of the cyclotron frequency
    for the species :math:`s`.

    References
    ----------
    - T.H. Stix, Waves in Plasma, 1992.

    Examples
    --------
    >>> from astropy import units as u
    >>> from plasmapy.constants import pi
    >>> B = 2*u.T
    >>> species = ['e', 'D+']
    >>> n = [1e18*u.m**-3, 1e18*u.m**-3]
    >>> omega = 3.7e9*(2*pi)*(u.rad/u.s)
    >>> L, R, P = cold_plasma_permittivity_LRP(B, species, n, omega)
    >>> L
    <Quantity 0.63333549>
    >>> R
    <Quantity 1.41512254>
    >>> P
    <Quantity -4.8903104>
    """
    L, R, P = 1, 1, 1

    for s, n_s in zip(species, n):
        omega_c = parameters.gyrofrequency(B=B, particle=s, signed=True)
        omega_p = parameters.plasma_frequency(n=n_s, particle=s)

        L += -omega_p**2 / (omega * (omega - omega_c))
        R += -omega_p**2 / (omega * (omega + omega_c))
        P += -omega_p**2 / omega**2
    return L, R, P
예제 #11
0
def wave_growth_oblique_m(name, density, B, T_perp, T_para, waveperOmega,
                          distribution, theta_input, m):
    """
    Calculate the m part of growth_rate
    Based on Kennel 1966
    """
    if name == 'e':
        n = density[0]
    else:
        n = density[1]

    electron = particle.particles(name, n, B, T_perp, T_para)
    species = ['e', 'p']
    theta_deg = theta_input * pi / 180
    # Here is positive signed = False
    gyro_frequency = parameters.gyrofrequency(B, name)
    wave_frequency = waveperOmega * gyro_frequency
    # First need to

    # Fist solve the refraction_index
    refraction_index_para = disper.solve_dispersion(B, species, density,
                                                    wave_frequency,
                                                    theta_input)

    Omega = electron.gyro_f.value
    ww = wave_frequency.value

    c = const.c.value
    kk = refraction_index_para * ww / c
    kk_para = kk * cos(theta_deg)
    kk_perp = kk * sin(theta_deg)

    # set the symbol
    vx = symbols('vx')
    vz = symbols('vz')
    vth_x = symbols('vth_x')
    vth_z = symbols('vth_z')
    r = symbols('r')
    w = symbols('w')
    k_para = symbols('k_para')
    theta = symbols('theta')

    # First integrate the v_parallel
    # we need four term
    # G1, weight function, Dirac Function, vx**2
    # First integrate v_parallel
    G1_term1, G1_term2 = electron.G_1(distribution)
    G1 = G1_term1 - (kk_para / ww) * G1_term2
    v_para_int = integrate(
        G1 * electron.delta_function(m).subs([(w, ww), (k_para, kk_para)]),
        (vz, -oo, oo))
    print(v_para_int)

    if electron.name == 'e':
        flag = -1
    else:
        flag = 1
    # flag determin the r integrate range -1 means -oo to 0
    # 1 means 0 to oo

    ### The reason here need to change that is because the Jm integration can not with parameters
    v_para_int_value = (v_para_int.subs([(vth_x, electron.vth_x),
                                         (vth_z, electron.vth_z)]))
    #v_perp_int_value = v_para_int_value * vx**2 * electron.weight_function_p(m)
    # # change the vx to (k *v / Omega) and input the vth_z and vth_x
    r_vx = r * Omega / kk_perp
    v_para_int_value_new = v_para_int_value.subs(vx, r_vx)

    v_perp_int = v_para_int_value_new * (
        (Omega / kk_perp)**3 * r**2 * electron.weight_function_p(m)).subs(
            theta, theta_deg)
    # Dothe simplify?
    #v_perp_int_test = simplify(v_perp_int)
    print("vy success")
    #Now do the final integration!
    if flag == -1:

        v_perp_int_value = integrate(v_perp_int, (r, -oo, 0))
    else:
        v_perp_int_value = integrate(v_perp_int, (r, 0, oo))
    growth_rate_oblique = (-pi**2 * Omega * ww / kk) * v_perp_int_value
    return growth_rate_oblique.evalf()
예제 #12
0
def wave_growth_para(name, density, B, T_perp, T_para, waveperOmega,
                     distribution):
    if name == 'e':
        n = density[0]
    else:
        n = density[1]

    electron = particle.particles(name, n, B, T_perp, T_para)
    species = ['e', 'p']
    theta_input = 0
    theta_deg = theta_input * pi / 180

    gyro_frequency = parameters.gyrofrequency(B, name)
    wave_frequency = waveperOmega * gyro_frequency

    refraction_index_para = disper.solve_dispersion(B, species, density,
                                                    wave_frequency,
                                                    theta_input)
    print("nn", refraction_index_para)
    vx = symbols('vx')
    vz = symbols('vz')
    vth_x = symbols('vth_x')
    vth_z = symbols('vth_z')
    # Tx = symbols('Tx')
    # Tz = symbols('Tz')
    f = electron.F_0()
    # result_x = integrate(f, (vz, -oo, oo))
    # result = integrate(2 * pi * vx * result_x, (vx, 0, oo))

    # set w and Omega and k
    Omega = gyro_frequency.value
    w = wave_frequency.value

    c = const.c.value
    k = refraction_index_para * w / c
    k_para = k * cos(theta_deg)
    k_para_c = k_para * c

    #print(result)
    G1_term1, G1_term2 = electron.G_1(distribution)
    print(G1_term1, G1_term2, f)
    # print(G1_term1, G1_term2)
    #print(refraction_index_para)
    G1 = G1_term1 - (k_para / w) * G1_term2

    G1_para = -(k_para / w) * G1_term2
    #
    vz_res = (w - Omega) / (k_para)
    G1_new = (G1.subs(vz, vz_res))
    print("test!!")
    print(G1_new)
    # G1_res = G1_para.subs(vz, (w - Omega) / (k_para))
    #print(G1_res)
    # wave_growth_para_coeff= pi**2 * Omega*c/n
    wave_para_int = (pi**2 * Omega * w / k) * integrate(
        vx**2 * G1_new, (vx, 0, oo))
    wave_para_int_new = wave_para_int.subs([(vth_x, electron.vth_x),
                                            (vth_z, electron.vth_z)])
    print(wave_para_int_new)
    #wave_growth_eva = wave_para_int.subs(vz, vz_res)
    #print(wave_para_int)
    return wave_para_int_new, vz_res, G1_new
예제 #13
0
############################################################
# Initialize the fields. We'll take B in the x direction
# and E in the y direction, which gets us an E cross B drift
# in the z direction.

B0 = 4 * u.T
plasma.magnetic_field[0, :, :, :] = np.ones((10, 10, 10)) * B0

E0 = 2 * u.V / u.m
plasma.electric_field[1, :, :, :] = np.ones((10, 10, 10)) * E0

############################################################
# Calculate the timestep. We'll take one proton `p`, take its gyrofrequency, invert that
# to get to the gyroperiod, and resolve that into 10 steps for higher accuracy.

freq = gyrofrequency(B0, 'p').to(u.Hz, equivalencies=u.dimensionless_angles())
gyroperiod = (1/freq).to(u.s)
steps_to_gyroperiod = 10
timestep = gyroperiod / steps_to_gyroperiod

############################################################
# Initialize the trajectory calculation.

number_steps = steps_to_gyroperiod * int(2 * np.pi)
trajectory = ParticleTracker(plasma, 'p', 1, 1, timestep, number_steps)

############################################################
# We still have to initialize the particle's velocity. We'll limit ourselves to
# one in the x direction, parallel to the magnetic field B -
# that way, it won't turn in the z direction.
예제 #14
0
import numpy as np
import matplotlib.pyplot as plt
import cold_growth_rate
from sympy import ln
import particle
from scipy.optimize import fsolve
from astropy import constants as const
from sympy import sin, cos, exp

species = ['e', 'p']

B = 1e-6 * u.T
n = [300e6 * u.m**-3, 300e6 * u.m**-3]
theta_input = 0
theta_deg = theta_input * pi / 180
gyro_frequency = parameters.gyrofrequency(B, 'e')
wave_frequency = 0.05 * gyro_frequency
print(wave_frequency)

#%%

# test dispersion  solve
refraction_index = disper.solve_dispersion(B, species, n, wave_frequency,
                                           theta_input)
print(refraction_index)
# Draw a picture of n and w/Omega

x = np.arange(0.1, 0.5, 0.005)
refraction_index_array = np.zeros(len(x))
print(refraction_index_array)
refraction_index_array = []