Example #1
0
def test_mcnp_id():
    assert_equal(mcnp("Neutron"), "n")
    assert_equal(mcnp(2112), "n")
    assert_equal(mcnp("Photon"), "p")
    assert_equal(mcnp("Gamma"), "p")
    assert_equal(mcnp("Electron"), "e")
Example #2
0
def magic(meshtally, tag_name, tag_name_error, **kwargs):
    """This function reads a PyNE mcnp.MeshTally object and preforms the MAGIC
    algorithm and returns the resulting weight window mesh.

    Parameters:
    -----------
    meshtally : a single PyNE mcnp.MeshTally obj
    tag_name : string
        The meshtally tag_name (example: n_result or n_total_result).
    tag_name_error : string
        The meshtally tag_name for the error associated with provided tag_name.
        Example: n_rel_error
    tolerance : float, optional
        The maximum relative error allowable for the MAGIC algorithm to create
        a weight window lower bound for for a given mesh volume element for the
        intial weight window lower bound generation, or overwrite preexisting
        weight window lower bounds for subsequent iterations.
    null_value : float, optional
        The weight window lower bound value that is assigned to mesh volume
        elements where the relative error on flux exceeds the tolerance.
    """

    tolerance = kwargs.get('tolerance', 0.5)
    null_value = kwargs.get('null_value', 0.0)

    # Convert particle name to the recognized abbreviation
    particle = (meshtally.particle.capitalize())
    if particle == ("Neutron" or "Photon" or "Electron"):
        meshtally.particle = mcnp(particle).lower()

    # Create tags for values and errors
    meshtally.vals = NativeMeshTag(mesh=meshtally, name=tag_name)
    meshtally.errors = NativeMeshTag(mesh=meshtally, name=tag_name_error)

    # Create weight window tags
    tag_size = meshtally.vals[0].size
    meshtally.ww_x = NativeMeshTag(tag_size,
                                   float,
                                   name="ww_{0}".format(meshtally.particle))
    meshtally.tag("{0}_e_upper_bounds".format(meshtally.particle),
                  np.zeros(tag_size, dtype=float),
                  'nat_mesh',
                  size=tag_size,
                  dtype=float)
    root_tag = meshtally.get_tag("{0}_e_upper_bounds".format(
        meshtally.particle))
    # Determine if total energy or single energy bin or multiple energy bins
    if tag_size == 1 and len(meshtally.e_bounds) > 1:
        total = True
    elif tag_size == 1 and len(meshtally.e_bounds) == 1:
        total = True
    elif tag_size > 1 and len(meshtally.e_bounds) > 1:
        total = False

    # Reassign arrays for total and not total case
    if total:
        # get value tagged on the mesh itself
        root_tag[meshtally] = np.max(meshtally.e_bounds[:])
        max_val = np.max(meshtally.vals[:])

        vals = []
        errors = []
        for flux, error in zip(meshtally.vals[:], meshtally.errors[:]):
            vals.append(np.atleast_1d(flux))
            errors.append(np.atleast_1d(error))

        vals = np.array(vals)
        errors = np.array(errors)

    else:
        root_tag[meshtally] = meshtally.e_bounds[1:]
        vals = meshtally.vals[:]
        errors = meshtally.errors[:]

    # Determine the max values for each energy bin
    max_val = []
    for i in range(tag_size):
        vals_in_e = []
        for ve, flux in enumerate(vals[:]):
            vals_in_e.append(vals[ve][i])
        max_val.append(np.max(vals_in_e))

    # Apply normalization to create weight windows
    ww = []
    for ve, flux_list in enumerate(vals[:]):
        tally_list = errors[ve]
        flux = []
        for i, value in enumerate(flux_list):
            if tally_list[i] > tolerance:
                flux.append(null_value)
            else:
                flux.append(value / (2.0 * max_val[i]))
        ww.append(flux)

    # Resassign weight windows to meshtally
    if total:
        meshtally.ww_x[:] = np.reshape(ww, len(ww))
    else:
        meshtally.ww_x[:] = ww

    # Create wwinp mesh
    wwinp = Wwinp()
    wwinp.read_mesh(meshtally.mesh)
Example #3
0
def test_mcnp_id():
    assert_equal(mcnp("Neutron"),"N")
    assert_equal(mcnp(2112),"N")
    assert_equal(mcnp("Photon"),"P")
    assert_equal(mcnp("Gamma"),"P")
    assert_equal(mcnp("Electron"),"E")