def test_particle_mass_for_hydrogen_with_no_mass_number(): """Test that `particle_mass` does not return the proton mass when no mass number is specified for hydrogen. In this case, the standard atomic weight should be used to account for the small fraction of deuterium.""" assert particle_mass("H", Z=1) > const.m_p assert particle_mass("hydrogen", Z=1) > const.m_p
def test_particle_mass_equivalent_args(arg1, kwargs1, arg2, kwargs2, expected): """Test that `particle_mass` returns equivalent results for equivalent positional and keyword arguments.""" result1 = particle_mass(arg1, **kwargs1) result2 = particle_mass(arg2, **kwargs2) assert u.isclose(result1, result2), ( f"particle_mass({repr(arg1)}, **{kwargs1}) = {repr(result1)}, whereas " f"particle_mass({repr(arg2)}, **{kwargs2}) = {repr(result2)}. " f"These results are not equivalent as expected.") if expected is not None: assert u.isclose(result1, result2) and u.isclose(result2, expected), ( f"particle_mass({repr(arg1)}, **{kwargs1}) = {repr(result1)} and " f"particle_mass({repr(arg2)}, **{kwargs2}) = {repr(result2)}, but " f"these results are not equal to {repr(expected)} as expected.")
def __init__( self, plasma, particle_type="p", n_particles=1, scaling=1, dt=np.inf * u.s, nt=np.inf, integrator="explicit_boris", ): if np.isinf(dt) and np.isinf(nt): # coverage: ignore raise ValueError("Both dt and nt are infinite.") self.q = atomic.charge_number(particle_type) * constants.e.si self.m = atomic.particle_mass(particle_type) self.N = int(n_particles) self.scaling = scaling self.eff_q = self.q * scaling self.eff_m = self.m * scaling self.plasma = plasma self.dt = dt self.NT = int(nt) self.t = np.arange(nt) * dt self.x = np.zeros((n_particles, 3), dtype=float) * u.m self.v = np.zeros((n_particles, 3), dtype=float) * (u.m / u.s) self.name = particle_type self.position_history = np.zeros( (self.NT, *self.x.shape), dtype=float) * u.m self.velocity_history = np.zeros( (self.NT, *self.v.shape), dtype=float) * (u.m / u.s) # create intermediate array of dimension (nx,ny,nz,3) in order to allow # interpolation on non-equal spatial domain dimensions _B = np.moveaxis(self.plasma.magnetic_field.si.value, 0, -1) _E = np.moveaxis(self.plasma.electric_field.si.value, 0, -1) self.integrator = self._all_integrators[integrator] self._B_interpolator = interp.RegularGridInterpolator( (self.plasma.x.si.value, self.plasma.y.si.value, self.plasma.z.si.value), _B, method="linear", bounds_error=True, ) self._E_interpolator = interp.RegularGridInterpolator( (self.plasma.x.si.value, self.plasma.y.si.value, self.plasma.z.si.value), _E, method="linear", bounds_error=True, )
def setup_class(self): """set up some initial values for tests""" self.T_e = 1000 * u.eV self.n_e = 2e13 / u.cm**3 self.ion = "D +1" self.m_i = particle_mass(self.ion) self.Z = charge_number(self.ion) self.T_i = self.T_e self.n_i = self.n_e / self.Z self.B = 0.01 * u.T self.coulomb_log_val_ei = 17 self.coulomb_log_val_ii = 17 self.hall_e = None self.hall_i = None self.V_ei = None self.V_ii = None self.mu = m_e / self.m_i self.theta = self.T_e / self.T_i self.model = "Braginskii" self.field_orientation = "all" with pytest.warns(RelativityWarning): self.ct = ClassicalTransport( T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, Z=self.Z, B=self.B, model=self.model, field_orientation=self.field_orientation, coulomb_log_ei=self.coulomb_log_val_ei, coulomb_log_ii=self.coulomb_log_val_ii, V_ei=self.V_ei, V_ii=self.V_ii, hall_e=self.hall_e, hall_i=self.hall_i, mu=self.mu, theta=self.theta, ) self.ct_wrapper = ClassicalTransport( T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, Z=self.Z, B=self.B, model=self.model, field_orientation=self.field_orientation, mu=self.mu, theta=self.theta, ) self.all_variables = self.ct.all_variables
def test_particle_mass_helium(): """Test miscellaneous cases for `particle_mass`.""" assert particle_mass("alpha") > particle_mass("He-3 2+")
def test_particle_mass_berkelium_249(): """Test that `particle_mass` returns the correct value for Bk-249.""" assert np.isclose( particle_mass("berkelium-249").to(u.u).value, 249.0749877), "Incorrect isotope mass for berkelium."
"mass_numb": 3 }, None], ["T+", {}, "H-3+", {}, None], ["T+", {}, "T 1+", {}, None], ["Tritium+", {}, "T", { "Z": 1 }, None], [ "Fe-56 1+", {}, "Fe", { "mass_numb": 56, "Z": 1 }, particle_mass("Fe-56 1-") - 2 * const.m_e, ], ["Fe-56 +1", {}, 26, { "mass_numb": 56, "Z": 1 }, None], ] @pytest.mark.parametrize("arg1, kwargs1, arg2, kwargs2, expected", equivalent_particle_mass_args) def test_particle_mass_equivalent_args(arg1, kwargs1, arg2, kwargs2, expected): """Test that `particle_mass` returns equivalent results for equivalent positional and keyword arguments.""" result1 = particle_mass(arg1, **kwargs1)