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_spitzer_vs_formulary(self): """Spitzer resistivity should agree with approx. in NRL formulary""" with pytest.warns(RelativityWarning): ct2 = ClassicalTransport( T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, model="spitzer", field_orientation="perp", ) alpha_spitzer_perp_NRL = ( 1.03e-4 * ct2.Z * ct2.coulomb_log_ei * (ct2.T_e.to(u.eV, equivalencies=u.temperature_energy())).value ** (-3 / 2) * u.Ohm * u.m ) testTrue = np.isclose( ct2.resistivity.value, alpha_spitzer_perp_NRL.value, rtol=2e-2 ) errStr = ( f"Resistivity should be close to " f"{alpha_spitzer_perp_NRL.value} " f"and not {ct2.resistivity.value}." ) assert testTrue, errStr
def test_hall_calc(self): """if no hall parameters are input, they should be calculated""" with pytest.warns(RelativityWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion) hall_i = Hall_parameter(ct2.n_i, ct2.T_i, ct2.B, ct2.ion, ct2.ion, ct2.coulomb_log_ii, ct2.V_ii) hall_e = Hall_parameter( ct2.n_e, ct2.T_e, ct2.B, ct2.ion, ct2.e_particle, ct2.coulomb_log_ei, ct2.V_ei, ) testTrue = hall_i == ct2.hall_i errStr = f"Ion hall parameter should be {hall_i} and not {ct2.hall_i}." assert testTrue, errStr testTrue = hall_e == ct2.hall_e errStr = f"Electron hall parameter should be {hall_e} and not {ct2.hall_e}." assert testTrue, errStr
def test_invalid_field(self): with pytest.raises(ValueError): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, field_orientation='to the left')
def test_invalid_model(self): with pytest.raises(ValueError): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, model="standard")
def test_coulomb_log_errors(self): """should raise PhysicsError if coulomb log is < 1""" with pytest.raises(PhysicsError), pytest.warns(CouplingWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, coulomb_log_ii=0.3) with pytest.raises(PhysicsError), pytest.warns(CouplingWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, coulomb_log_ei=0.3)
def test_coulomb_log_warnings(self): """should warn CouplingWarning if coulomb log is near 1""" with pytest.warns(CouplingWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, coulomb_log_ii=1.3) with pytest.warns(CouplingWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, coulomb_log_ei=1.3)
def test_particle_mass(self): """should raise ValueError if particle mass not found""" with pytest.raises(ValueError): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion='empty moment', Z=1)
def test_Z_checks(self): """should raise ValueError if Z is negative""" with pytest.raises(ValueError): ct2 = 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=-1)
def test_particle_charge_state(self): """should raise ValueError if particle charge state not found""" with pytest.raises(InvalidParticleError): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion='empty moment', m_i=m_p)
def test_resistivity_by_model(self, model, expected): with pytest.warns(RelativityWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, model=model) testTrue = np.isclose(ct2.resistivity, expected, atol=1e-6 * u.Ohm * u.m) errStr = (f"Resistivity in {model} model should be " f"close to {expected} and not {ct2.resistivity}.") assert testTrue, errStr
def test_ion_thermal_conductivity_by_model(self, model, expected): with pytest.warns(RelativityWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, model=model) testTrue = np.allclose(ct2.ion_thermal_conductivity, expected, atol=1e-6 * u.W / (u.K * u.m)) errStr = (f"Ion thermal conductivity in {model} model " f"should be close to {expected} and not " f"{ct2.ion_thermal_conductivity}.") assert testTrue, errStr
def test_ion_viscosity_by_model(self, model, expected): with pytest.warns(RelativityWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, model=model) testTrue = np.allclose(ct2.ion_viscosity, expected, atol=1e-6 * u.Pa * u.s) errStr = ( f"Electron viscosity in {model} model should be close to " f"{expected} and not {ct2.electron_viscosity}") assert testTrue, errStr
def test_thermoelectric_conductivity_by_model(self, model, expected): with pytest.warns(RelativityWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, model=model) testTrue = np.isclose(ct2.thermoelectric_conductivity, expected, atol=1e-6 * u.s / u.s) errStr = (f"Thermoelectric conductivity in {model} model " f"should be close {expected} and not " f"{ct2.thermoelectric_conductivity}.") assert testTrue, errStr
def test_precalculated_parameters(self): with pytest.warns(RelativityWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, hall_i=0, hall_e=0) testTrue = np.isclose(ct2.resistivity, 2.8184954e-8 * u.Ohm * u.m, atol=1e-6 * u.Ohm * u.m) errStr = ( f"Resistivity should be close to " f"{2.8184954e-8 * u.Ohm * u.m} and not {ct2.resistivity}.") assert testTrue, errStr
def test_number_of_returns(self, model, attr_name, field_orientation, expected): with pytest.warns(RelativityWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion, model=model, field_orientation=field_orientation) attr_to_test = getattr(ct2, attr_name) testTrue = np.size(attr_to_test) == expected errStr = (f"{attr_name} in {model} model returns " f"{np.size(attr_to_test)} objects. " f"Expected to return {expected} objects.") assert testTrue, errStr
def test_coulomb_log_calc(self): """if no coulomb logs are input, they should be calculated""" with pytest.warns(RelativityWarning): ct2 = ClassicalTransport(T_e=self.T_e, n_e=self.n_e, T_i=self.T_i, n_i=self.n_i, ion=self.ion) cl_ii = Coulomb_logarithm(self.T_i, self.n_e, [self.ion, self.ion], self.V_ii) cl_ei = Coulomb_logarithm(self.T_e, self.n_e, ["e", self.ion], self.V_ei) testTrue = cl_ii == ct2.coulomb_log_ii errStr = (f"Ion-ion coulomb logarithm should be {cl_ii} " f"and not {ct2.coulomb_log_ii}.") assert testTrue, errStr testTrue = cl_ei == ct2.coulomb_log_ei errStr = (f"Electron-ion coulomb logarithm should be {cl_ei} " f"and not {ct2.coulomb_log_ei}.") assert testTrue, errStr