Пример #1
0
    def __setitem__(self, key, value):
        """Key setting via custom cache functionality."""
        # Set the E_g
        if (key == 'E_g'):
            value = np.array(value, dtype=float)

            # If the E_gs are the same, don't set anything
            if ('E_g' in self):
                if (len(value) == len(self['E_g'])) and (value == self['E_g']).all():
                    return 

            # Otherwise, preload some stuff.
            self._cache['partial_energy_matrix'] = partial_energy_matrix(value, self['E_n'])

            # And remove any previous paramters dependent on E_g
            dirty_keys = [k for k in self._cache if is_g_indexed(k)]
            for dk in dirty_keys:
                del self._cache[dk]


        # Set the E_n
        if (key == 'E_n'):
            value = np.array(value, dtype=float)
            
            # If the E_gs are the same, don't set anything
            if ('E_n' in self):
                if (len(value) == len(self['E_n'])) and (value == self['E_n']).all():
                    return 

            # Otherwise, preload some stuff.
            if 'E_g' in self:
                self._cache['partial_energy_matrix'] = partial_energy_matrix(self['E_g'], value)


        # Set the high resolution flux, phi_n
        if key == 'phi_n':
            value = np.array(value, dtype=float)

            # If the flux is same, don't set or remove anything
            if ('phi_n' in self):
                if (len(value) == len(self['phi_n'])) and (value == self['phi_n']).all():
                    return 

            # And remove any previous paramters dependent on phi_n
            dirty_keys = [k for k in self._cache if (is_g_indexed(k) and k != 'E_g')]
            for dk in dirty_keys:
                del self._cache[dk]

        # Set the value normally
        self._cache[key] = value
Пример #2
0
def test_partial_energy_matrix2():
    E_g = np.array([8.0, 4.0, 0.0])
    E_n = np.array([10.0, 7.5, 5.0, 2.5, 0.0])

    pem = partial_energy_matrix(E_g, E_n)

    expected = np.array([[0.2, 1.0, 0.4, 0.0], [0.0, 0.0, 0.6, 1.0]])

    assert_array_equal(pem, expected)
Пример #3
0
 def dst_group_struct(self, dst_group_struct):
     if dst_group_struct is None:
         self._dst_group_struct = None
         self._dst_ngroups = 0
         self._src_to_dst_matrix = None
     else:
         self._dst_group_struct = np.asarray(dst_group_struct)
         self._dst_ngroups = len(dst_group_struct) - 1
         self._src_to_dst_matrix = partial_energy_matrix(dst_group_struct, 
                                                         self._src_group_struct)
Пример #4
0
def test_partial_energy_matrix1():
    # tests dispach to inc
    E_g = np.array([0.0, 4.0, 8.0])
    E_n = np.array([0.0, 2.5, 5.0, 7.5, 10.0])

    pem = partial_energy_matrix(E_g, E_n)

    expected = np.array([[1.0, 0.6, 0.0, 0.0], [0.0, 0.4, 1.0, 0.2]])

    assert_array_equal(pem, expected)
Пример #5
0
def test_partial_energy_matrix2():
    E_g = np.array([8.0, 4.0, 0.0])
    E_n = np.array([10.0, 7.5, 5.0, 2.5, 0.0])

    pem = partial_energy_matrix(E_g, E_n)

    expected = np.array([[0.2, 1.0, 0.4, 0.0], 
                         [0.0, 0.0, 0.6, 1.0]])

    assert_array_equal(pem, expected)    
Пример #6
0
def test_partial_energy_matrix1():
    # tests dispach to inc
    E_g = np.array([0.0, 4.0, 8.0])
    E_n = np.array([0.0, 2.5, 5.0, 7.5, 10.0])

    pem = partial_energy_matrix(E_g, E_n)

    expected = np.array([[1.0, 0.6, 0.0, 0.0], 
                         [0.0, 0.4, 1.0, 0.2]])

    assert_array_equal(pem, expected)    
Пример #7
0
def test_group_collapse1():
    E_g = np.array([0.0, 4.0, 8.0])
    E_n = np.array([0.0, 2.5, 5.0, 7.5, 10.0])

    phi_n = np.array([0.0, 2.0, 1.0, 0.5])
    sigma_n = np.array([1.0, 2.0, 3.0, 4.0])

    expected = np.array([2.0, 5.0 / 1.9])

    # First way of calling
    observed = group_collapse(sigma_n, phi_n, E_g=E_g, E_n=E_n)
    assert_array_almost_equal(observed, expected)

    # Second method of calling
    p_g = phi_g(E_g, E_n, phi_n)
    pem = partial_energy_matrix(E_g, E_n)
    observed = group_collapse(sigma_n, phi_n, phi_g=p_g, partial_energies=pem)
    assert_array_almost_equal(observed, expected)

    # bad call
    assert_raises(ValueError, group_collapse, sigma_n, phi_n)
Пример #8
0
def test_group_collapse1():
    E_g = np.array([0.0, 4.0, 8.0])
    E_n = np.array([0.0, 2.5, 5.0, 7.5, 10.0])

    phi_n = np.array([0.0, 2.0, 1.0, 0.5])
    sigma_n = np.array([1.0, 2.0, 3.0, 4.0])

    expected = np.array([2.0, 5.0 / 1.9])

    # First way of calling
    observed = group_collapse(sigma_n, phi_n, E_g=E_g, E_n=E_n)
    assert_array_almost_equal(observed, expected)

    # Second method of calling
    p_g = phi_g(E_g, E_n, phi_n)
    pem = partial_energy_matrix(E_g, E_n)
    observed = group_collapse(sigma_n, phi_n, phi_g=p_g, partial_energies=pem)
    assert_array_almost_equal(observed, expected)

    # bad call
    assert_raises(ValueError, group_collapse, sigma_n, phi_n)