def test_iteration(self, test_name: str):
        """Test that IonizationState instances iterate impeccably."""
        try:
            states = [state for state in self.instances[test_name]]
        except Exception:
            raise AtomicError(f"Unable to perform iteration for {test_name}.")

        try:
            integer_charges = [state.integer_charge for state in states]
            ionic_fractions = np.array(
                [state.ionic_fraction for state in states])
            ionic_symbols = [state.ionic_symbol for state in states]
        except Exception:
            raise AtomicError("An attribute may be misnamed or missing.")

        try:
            base_symbol = isotope_symbol(ionic_symbols[0])
        except InvalidIsotopeError:
            base_symbol = atomic_symbol(ionic_symbols[0])
        finally:
            atomic_numb = atomic_number(ionic_symbols[1])

        errors = []

        expected_charges = np.arange(atomic_numb + 1)
        if not np.all(integer_charges == expected_charges):
            errors.append(
                f"The resulting integer charges are {integer_charges}, "
                f"which are not equal to the expected integer charges, "
                f"which are {expected_charges}.")

        expected_fracs = test_cases[test_name]['ionic_fractions']
        if isinstance(expected_fracs, u.Quantity):
            expected_fracs = (expected_fracs / expected_fracs.sum()).value

        if not np.allclose(ionic_fractions, expected_fracs):
            errors.append(
                f"The resulting ionic fractions are {ionic_fractions}, "
                f"which are not equal to the expected ionic fractions "
                f"of {expected_fracs}.")

        expected_particles = [
            Particle(base_symbol, Z=charge) for charge in integer_charges
        ]
        expected_symbols = [
            particle.ionic_symbol for particle in expected_particles
        ]
        if not ionic_symbols == expected_symbols:
            errors.append(
                f"The resulting ionic symbols are {ionic_symbols}, "
                f"which are not equal to the expected ionic symbols of "
                f"{expected_symbols}.")

        if errors:
            errors.insert(
                0, (f"The test of IonizationState named '{test_name}' has "
                    f"resulted in the following errors when attempting to "
                    f"iterate."))
            errmsg = " ".join(errors)
            raise AtomicError(errmsg)
Beispiel #2
0
def test_instantiation(atomic_numb):
    try:
        element_symbol = atomic.atomic_symbol(int(atomic_numb))
        EigenData(element=element_symbol)
    except Exception as exc:
        raise Exception(
            f"Problem with instantiation for atomic number={atomic_numb}."
        ) from exc
Beispiel #3
0
def test_element_range():
    """
    Function test_element_range:
        This function is used to test element including Hydrogen to Iron.
    """
    atomic_numb = np.linspace(1, 26, 26, endpoint=True)
    for i in atomic_numb:
        element_symbol = atomic.atomic_symbol(int(i))
        eigen = nei.EigenData2(element=element_symbol)
        print(f'Element: ', element_symbol)
def test_element_range(atomic_numb):
    """
    Function test_element_range:
        This function is used to test element including Hydrogen to Iron.
    """
    try:
        element_symbol = atomic.atomic_symbol(int(atomic_numb))
        eigen = EigenData2(element=element_symbol)
    except Exception as exc:
        raise Exception(f"Problem with atomic number={atomic_numb}.") from exc

    eigen=0  # attempt to clear up memory
def test_reachequlibrium_state_multisteps(natom=8):
    """
        Starting the random initial distribution, the charge states will reach
        to equilibrium cases after a long time (multiple steps).
        In this test, we set the ionization and recombination rates at
        Te0=2.0e6 K and plasma density ne0=1.0e+7. A random charge states
        distribution will be finally closed to equilibrium distribution at
        2.0e6K.
    """
    #
    # Initial conditions, set plasma temperature, density and dt
    #
    element_symbol = atomic.atomic_symbol(int(natom))
    te0 = 1.0e+6 # unit: K
    ne0 = 1.0e+8 # unit: cm^-3

    # Start from any ionizaiont states, e.g., Te = 4.0d4 K,
    time = 0
    table = EigenData2(element=natom)
    f0 = table.equilibrium_state(T_e=4.0e+4)

    print('START test_reachequlibrium_state_multisteps:')
    print(f'time_sta = ', time)
    print(f'INI: ', f0)
    print(f'Sum(f0) = ', np.sum(f0))

    # After time + dt:
    dt = 100000.0 # unit: second

    # Enter the time loop:
    for it in range(100):
        ft = func_solver_eigenval(natom, te0, ne0, time+dt, f0, table)
        f0 = np.copy(ft)
        time = time+dt

    print(f'time_end = ', time+dt)
    print(f'NEI:', ft)
    print(f'Sum(ft) = ', np.sum(ft))

    assert np.isclose(np.sum(ft), 1)

    print(f"EI :", table.equilibrium_state(T_e=te0))
    print("End Test.\n")
def test_reachequlibrium_state(natom):
    """
        Starting the random initial distribution, the charge states will reach
        to equilibrium cases after a long time.
        In this test, we set the ionization and recombination rates at
        Te0=2.0e6 K and plasma density ne0=1.0e+7. A random charge states
        distribution will be finally closed to equilibrium distribution at
        2.0e6K.
    """
    #
    # Initial conditions, set plasma temperature, density and dt
    #
    element_symbol = atomic.atomic_symbol(int(natom))
    te0 = 1.0e+6
    ne0 = 1.0e+8

    # Start from any ionizaiont states, e.g., Te = 4.0d4 K,
    time = 0
    table = EigenData2(element=natom)
    f0 = table.equilibrium_state(T_e=4.0e4)

    print('START test_reachequlibrium_state:')
    print(f'time_sta = ', time)
    print(f'INI: ', f0)
    print(f'Sum(f0) = ', np.sum(f0))

    # After time + dt:
    dt = 1.0e+7
    ft = func_solver_eigenval(natom, te0, ne0, time+dt, f0, table)

    print(f'time_end = ', time+dt)
    print(f'NEI:', ft)
    print(f'Sum(ft) = ', np.sum(ft))
    print(f'EI :', table.equilibrium_state(T_e=te0))
    print("End Test.\n")

    assert np.isclose(np.sum(ft), 1), 'np.sum(ft) is not approximately 1'
    assert np.isclose(np.sum(f0), 1), 'np.sum(f0) is not approximately 1'
    assert np.allclose(ft, table.equilibrium_state(T_e=te0))