示例#1
0
def test_total_photon_source_intensity_subvoxel():
    # In the calculation of the total photon source intensities under subvoxel
    # mode, the volume fractions of each subvoxel should be multiplied

    # Set up 4 voxels with the volume of: 1, 2, 1, 2
    m = Mesh(structured=True, structured_coords=[[0, 1, 2], [0, 1, 3], [0, 1]])
    # 4 voxels, each voxel contains two subvoxels -> 8 subvoxels
    # The volume fraction of each subvoxel is 0.5
    cell_fracs = np.zeros(8,
                          dtype=[('idx', np.int64), ('cell', np.int64),
                                 ('vol_frac', np.float64),
                                 ('rel_error', np.float64)])
    cell_fracs[:] = [(0, 11, 0.5, 0.0), (0, 12, 0.5, 0.0), (1, 11, 0.5, 0.0),
                     (1, 12, 0.5, 0.0), (2, 13, 0.5, 0.0), (2, 11, 0.5, 0.0),
                     (3, 12, 0.5, 0.0), (3, 13, 0.5, 0.0)]
    m.tag_cell_fracs(cell_fracs)
    # Set up the source density with energy group number of 2
    m.source_density = NativeMeshTag(4, float)
    m.source_density[:] = [[0.0, 0.0, 1.0, 1.0], [2.0, 2.0, 3.0, 3.0],
                           [4.0, 4.0, 5.0, 5.0], [6.0, 6.0, 7.0, 7.0]]
    intensity = total_photon_source_intensity(m, "source_density", True)
    # expected intensity: each line represents a mesh voxel
    # for each subvoxel: voxel_vol * cell_fracs * photon_intensity
    expected_intensity = 1 * 0.5 * (0.0 + 0.0) + 1 * 0.5 * (1.0 + 1.0)
    expected_intensity += 2 * 0.5 * (2.0 + 2.0) + 2 * 0.5 * (3.0 + 3.0)
    expected_intensity += 1 * 0.5 * (4.0 + 4.0) + 1 * 0.5 * (5.0 + 5.0)
    expected_intensity += 2 * 0.5 * (6.0 + 6.0) + 2 * 0.5 * (7.0 + 7.0)
    assert_equal(intensity, expected_intensity)
示例#2
0
def test_total_photon_source_intensity():

    m = Mesh(structured=True, structured_coords=[[0, 1, 2], [0, 1, 3], [0, 1]])
    m.source_density = NativeMeshTag(2, float)
    m.source_density[:] = [[1., 2.], [3., 4.], [5., 6.], [7., 8.]]

    intensity = total_photon_source_intensity(m, "source_density")
    assert_equal(intensity, 58)
示例#3
0
def step2():
    config = ConfigParser.ConfigParser()
    config.read(config_filename)
    structured = config.getboolean("general", "structured")
    sub_voxel = config.getboolean("general", "sub_voxel")
    decay_times = config.get("step2", "decay_times").split(",")
    output = config.get("step2", "output")
    tot_phtn_src_intensities = config.get("step2", "tot_phtn_src_intensities")
    tag_name = "source_density"

    if sub_voxel:
        geom = config.get("step1", "geom")
        load(geom)
        cell_mats = cell_materials(geom)
    else:
        cell_mats = None
    h5_file = "phtn_src.h5"
    if not isfile(h5_file):
        photon_source_to_hdf5(filename="phtn_src", nucs="total")
    intensities = "Total photon source intensities (p/s)\n"
    e_bounds = phtn_src_energy_bounds("alara_inp")
    for i in range(len(e_bounds)):
        e_bounds[i] /= 1.0e6  # convert unit from eV to MeV
    for i, dt in enumerate(decay_times):
        print("Writing source for decay time: {0} to mesh".format(dt))
        mesh = Mesh(structured=structured, mesh="blank_mesh.h5m")
        tags = {("TOTAL", dt): tag_name}
        photon_source_hdf5_to_mesh(mesh,
                                   h5_file,
                                   tags,
                                   sub_voxel=sub_voxel,
                                   cell_mats=cell_mats)
        p_src_filename = "{0}_{1}.h5m".format(output, i + 1)
        intensity = total_photon_source_intensity(mesh,
                                                  tag_name,
                                                  sub_voxel=sub_voxel)
        mesh = tag_e_bounds(mesh, e_bounds)
        mesh = tag_source_intensity(mesh, intensity)
        # get and tag decay time
        decay_time = to_sec(float(dt.split()[0]), dt.split()[1])
        mesh = tag_decay_time(mesh, decay_time)
        # set version manually when changing the information of source.h5m
        mesh = tag_version(mesh)
        mesh.write_hdf5("{0}_{1}.h5m".format(output, i + 1))
        intensities += "{0}: {1}\n".format(dt, intensity)

    with open(tot_phtn_src_intensities, "w") as f:
        f.write(intensities)

    print("R2S step2 complete.")
示例#4
0
def step2():
    config = ConfigParser.ConfigParser()
    config.read(config_filename)
    structured = config.getboolean('general', 'structured')
    sub_voxel = config.getboolean('general', 'sub_voxel')
    decay_times = config.get('step2', 'decay_times').split(',')
    output = config.get('step2', 'output')
    tot_phtn_src_intensities = config.get('step2', 'tot_phtn_src_intensities')
    tag_name = "source_density"

    if sub_voxel:
        geom = config.get('step1', 'geom')
        load(geom)
        cell_mats = cell_materials(geom)
    else:
        cell_mats = None
    h5_file = 'phtn_src.h5'
    if not isfile(h5_file):
        photon_source_to_hdf5('phtn_src')
    intensities = "Total photon source intensities (p/s)\n"
    for i, dc in enumerate(decay_times):
        print('Writing source for decay time: {0}'.format(dc))
        mesh = Mesh(structured=structured, mesh='blank_mesh.h5m')
        tags = {('TOTAL', dc): tag_name}
        photon_source_hdf5_to_mesh(mesh,
                                   h5_file,
                                   tags,
                                   sub_voxel=sub_voxel,
                                   cell_mats=cell_mats)
        mesh.write_hdf5('{0}_{1}.h5m'.format(output, i + 1))
        intensity = total_photon_source_intensity(mesh,
                                                  tag_name,
                                                  sub_voxel=sub_voxel)
        intensities += "{0}: {1}\n".format(dc, intensity)

    with open(tot_phtn_src_intensities, 'w') as f:
        f.write(intensities)

    e_bounds = phtn_src_energy_bounds("alara_inp")
    e_bounds_str = ""
    for e in e_bounds:
        e = e / 1e6  # convert unit to MeV
        e_bounds_str += "{0}\n".format(e)
    with open("e_bounds", 'w') as f:
        f.write(e_bounds_str)

    print('R2S step2 complete.')
示例#5
0
def step2():
    config = ConfigParser.ConfigParser()
    config.read(config_filename)
    structured = config.getboolean('general', 'structured')
    sub_voxel = config.getboolean('general', 'sub_voxel')
    decay_times = config.get('step2', 'decay_times').split(',')
    output = config.get('step2', 'output')
    tot_phtn_src_intensities = config.get('step2', 'tot_phtn_src_intensities')
    tag_name = "source_density"

    if sub_voxel:
        geom = config.get('step1', 'geom')
        load(geom)
        cell_mats = cell_materials(geom)
    else:
        cell_mats = None
    h5_file = 'phtn_src.h5'
    if not isfile(h5_file):
        photon_source_to_hdf5(filename='phtn_src', nucs='total')
    intensities = "Total photon source intensities (p/s)\n"
    e_bounds = phtn_src_energy_bounds("alara_inp")
    for i in range(len(e_bounds)):
        e_bounds[i] /= 1.0e6 # convert unit from eV to MeV
    for i, dt in enumerate(decay_times):
        print('Writing source for decay time: {0} to mesh'.format(dt))
        mesh = Mesh(structured=structured, mesh='blank_mesh.h5m')
        tags = {('TOTAL', dt): tag_name}
        photon_source_hdf5_to_mesh(mesh, h5_file, tags, sub_voxel=sub_voxel,
                                   cell_mats=cell_mats)
        intensity = total_photon_source_intensity(mesh, tag_name,
                                                  sub_voxel=sub_voxel)
        mesh = tag_e_bounds(mesh, e_bounds)
        mesh = tag_source_intensity(mesh, intensity)
        # get and tag decay time
        decay_time = to_sec(float(dt.split()[0]), dt.split()[1])
        mesh = tag_decay_time(mesh, decay_time)
        # set version manually when changing the information of source.h5m
        mesh = tag_version(mesh)
        mesh.write_hdf5('{0}_{1}.h5m'.format(output, i+1))
        intensities += "{0}: {1}\n".format(dt, intensity)

    with open(tot_phtn_src_intensities, 'w') as f:
        f.write(intensities)

    print('R2S step2 complete.')