Ejemplo n.º 1
0
def test_file_almost_same():
    """
    Test utils.file_almost_same.
    """
    # exactly the same, w/o numbers
    f1 = """l1\nl2 string"""
    f2 = """l1\nl2 string"""
    assert (utils.file_almost_same(f1, f2))

    # almost the same, with numbers
    f1 = """l1\nl2 data 9.5"""
    f2 = """l1\nl2 data 9.5000000000001"""
    assert (utils.file_almost_same(f1, f2))

    # different contents
    f1 = """l1\nl2 string1"""
    f2 = """l1\nl2 string2"""
    assert (utils.file_almost_same(f1, f2) == False)
Ejemplo n.º 2
0
def test_record_to_geom():

    if not HAVE_PYMOAB:
        raise SkipTest

    expected_geom = os.path.join(thisdir, "files_test_alara",
                                 "alara_record_geom.txt")
    expected_matlib = os.path.join(thisdir, "files_test_alara",
                                   "alara_record_matlib.txt")
    geom = os.path.join(os.getcwd(), "alara_record_geom")
    matlib = os.path.join(os.getcwd(), "alara_record_matlib")
    cell_fracs = np.zeros(
        11,
        dtype=[
            ("idx", np.int64),
            ("cell", np.int64),
            ("vol_frac", np.float64),
            ("rel_error", np.float64),
        ],
    )

    cell_mats = {
        11:
        Material({
            "H1": 1.0,
            "K39": 1.0
        },
                 density=1.1,
                 metadata={"name": "fake_mat"}),
        12:
        Material({
            "H1": 0.1,
            "O16": 1.0
        },
                 density=1.2,
                 metadata={"name": "water"}),
        13:
        Material({"He4": 42.0}, density=1.3, metadata={"name": "helium"}),
        14:
        Material({}, density=0.0, metadata={"name": "void"}),
        15:
        Material({}, density=0.0, metadata={"name": "void"}),
        16:
        Material({
            "H1": 1.0,
            "K39": 1.0
        },
                 density=1.1,
                 metadata={"name": "fake_mat"}),
    }

    cell_fracs[:] = [
        (0, 11, 0.55, 0.0),
        (0, 12, 0.45, 0.0),
        (1, 11, 0.2, 0.0),
        (1, 12, 0.3, 0.0),
        (1, 13, 0.5, 0.0),
        (2, 11, 0.15, 0.0),
        (2, 14, 0.01, 0.0),
        (2, 15, 0.04, 0.0),
        (2, 16, 0.8, 0.0),
        (3, 11, 0.55, 0.0),
        (3, 12, 0.45, 0.0),
    ]

    m = Mesh(structured_coords=[[-1, 0, 1], [-1, 0, 1], [0, 1]],
             structured=True,
             mats=None)

    #    import pdb; pdb.set_trace()
    record_to_geom(m, cell_fracs, cell_mats, geom, matlib)

    assert file_almost_same(geom, expected_geom)
    if os.path.isfile(geom):
        os.remove(geom)

    assert filecmp.cmp(matlib, expected_matlib)
    if os.path.isfile(matlib):
        os.remove(matlib)
Ejemplo n.º 3
0
def _r2s_test_step2(r2s_run_dir, remove_step1_out=True):
    os.chdir(thisdir)
    # copy ../scripts/r2s.py to r2s_run_dir/r2s.py
    os.chdir("..")
    folderpath = os.getcwd()
    dst = os.path.join(r2s_run_dir, "r2s.py")
    copyfile(os.path.join(folderpath, "scripts", "r2s.py"), dst)

    # output files of r2s step1
    alara_inp = os.path.join(r2s_run_dir, "alara_inp")
    blank_mesh = os.path.join(r2s_run_dir, "blank_mesh.h5m")
    if remove_step1_out:
        copyfile(os.path.join(r2s_run_dir, "exp_alara_inp"), alara_inp)
        copyfile(os.path.join(r2s_run_dir, "exp_blank_mesh.h5m"), blank_mesh)

    # run r2s step2
    os.chdir(r2s_run_dir)
    os.system('python r2s.py step2')
    os.remove(blank_mesh)
    os.remove(alara_inp)
    os.remove(dst)

    # output files of r2s step2
    p_src = os.path.join(r2s_run_dir, "phtn_src.h5")
    os.remove(p_src)

    # compare the total photon source intensities
    t_p_src = os.path.join(r2s_run_dir, "total_photon_source_intensities.txt")
    exp_t_p_src = os.path.join(r2s_run_dir,
                               "exp_total_photon_source_intensities.txt")
    f5 = file_almost_same(t_p_src, exp_t_p_src)
    assert_equal(f5, True)
    os.remove(t_p_src)

    # compare the results
    src_c1 = os.path.join(r2s_run_dir, "source_1.h5m")
    exp_src_c1 = os.path.join(r2s_run_dir, "exp_source_1.h5m")
    # skip test if h5diff not exist
    if 'unstructured' in r2s_run_dir:
        ele_type = 'Tet4'
    else:
        ele_type = 'Hex8'
    is_h5diff = os.system('which h5diff')
    if is_h5diff == 0:
        # compare two h5 files
        f6 = True  # compre source_density
        command = ''.join([
            'h5diff --relative=1e-6 ', src_c1, ' ', exp_src_c1,
            ' /tstt/elements/', ele_type, '/tags/source_density',
            ' /tstt/elements/', ele_type, '/tags/source_density'
        ])
        diff_flag = os.system(command)
        # return value 0 if no difference, 1 if differences found, 2 if error
        f6 = True if diff_flag == 0 else False
        assert_equal(f6, True)

        # compare e_bounds
        f4 = True
        command = ''.join([
            'h5diff --relative=1e-6 ', src_c1, ' ', exp_src_c1,
            ' /tstt/tags/e_bounds', ' /tstt/tags/e_bounds'
        ])
        diff_flag = os.system(command)
        f4 = True if diff_flag == 0 else False
        assert_equal(f4, True)
        # compare decay_time
        f7 = True
        command = ''.join([
            'h5diff --relative=1e-6 ', src_c1, ' ', exp_src_c1,
            ' /tstt/tags/decay_time', ' /tstt/tags/decay_time'
        ])
        diff_flag = os.system(command)
        f7 = True if diff_flag == 0 else False
        assert_equal(f7, True)
        # compare total_photon_source_intensity
        f8 = True
        command = ''.join([
            'h5diff --relative=1e-6 ', src_c1, ' ', exp_src_c1,
            ' /tstt/tags/source_intensity', ' /tstt/tags/source_intensity'
        ])
        diff_flag = os.system(command)
        f8 = True if diff_flag == 0 else False
        assert_equal(f8, True)
        # compare r2s soruce file version
        f9 = True
        command = ''.join([
            'h5diff ', src_c1, ' ', exp_src_c1,
            ' /tstt/tags/r2s_source_file_version',
            ' /tstt/tags/r2s_source_file_version'
        ])
        diff_flag = os.system(command)
        f9 = True if diff_flag == 0 else False
        assert_equal(f9, True)

    os.remove(src_c1)
Ejemplo n.º 4
0
def test_record_to_geom():

    if not HAVE_PYMOAB:
        raise SkipTest

    expected_geom = os.path.join(thisdir, "files_test_alara",
                                 "alara_record_geom.txt")
    expected_matlib = os.path.join(thisdir, "files_test_alara",
                                   "alara_record_matlib.txt")
    geom = os.path.join(os.getcwd(), "alara_record_geom")
    matlib = os.path.join(os.getcwd(), "alara_record_matlib")
    cell_fracs = np.zeros(11,
                          dtype=[('idx', np.int64), ('cell', np.int64),
                                 ('vol_frac', np.float64),
                                 ('rel_error', np.float64)])

    cell_mats = {
        11:
        Material({
            'H1': 1.0,
            'K39': 1.0
        },
                 density=1.1,
                 metadata={'name': 'fake_mat'}),
        12:
        Material({
            'H1': 0.1,
            'O16': 1.0
        },
                 density=1.2,
                 metadata={'name': 'water'}),
        13:
        Material({'He4': 42.0}, density=1.3, metadata={'name': 'helium'}),
        14:
        Material({}, density=0.0, metadata={'name': 'void'}),
        15:
        Material({}, density=0.0, metadata={'name': 'void'}),
        16:
        Material({
            'H1': 1.0,
            'K39': 1.0
        },
                 density=1.1,
                 metadata={'name': 'fake_mat'})
    }

    cell_fracs[:] = [(0, 11, 0.55, 0.0), (0, 12, 0.45, 0.0), (1, 11, 0.2, 0.0),
                     (1, 12, 0.3, 0.0), (1, 13, 0.5, 0.0), (2, 11, 0.15, 0.0),
                     (2, 14, 0.01, 0.0), (2, 15, 0.04, 0.0), (2, 16, 0.8, 0.0),
                     (3, 11, 0.55, 0.0), (3, 12, 0.45, 0.0)]

    m = Mesh(structured_coords=[[-1, 0, 1], [-1, 0, 1], [0, 1]],
             structured=True,
             mats=None)

    #    import pdb; pdb.set_trace()
    record_to_geom(m, cell_fracs, cell_mats, geom, matlib)

    assert (file_almost_same(geom, expected_geom))
    if os.path.isfile(geom):
        os.remove(geom)

    assert (filecmp.cmp(matlib, expected_matlib))
    if os.path.isfile(matlib):
        os.remove(matlib)
Ejemplo n.º 5
0
def _r2s_test_step2(r2s_run_dir, remove_step1_out=True):
    os.chdir(thisdir)
    # copy ../scripts/r2s.py to r2s_run_dir/r2s.py
    os.chdir("..")
    folderpath = os.getcwd()
    dst = os.path.join(r2s_run_dir, "r2s.py")
    copyfile(os.path.join(folderpath, "scripts", "r2s.py"), dst)

    # output files of r2s step1
    alara_inp = os.path.join(r2s_run_dir, "alara_inp")
    blank_mesh = os.path.join(r2s_run_dir, "blank_mesh.h5m")
    if remove_step1_out:
        copyfile(os.path.join(r2s_run_dir, "exp_alara_inp"), alara_inp)
        copyfile(os.path.join(r2s_run_dir, "exp_blank_mesh.h5m"), blank_mesh)

    # run r2s step2
    os.chdir(r2s_run_dir)
    os.system('python r2s.py step2')

    # output files of r2s step2
    e_bounds = os.path.join(r2s_run_dir, "e_bounds")
    p_src = os.path.join(r2s_run_dir, "phtn_src.h5")
    t_p_src = os.path.join(r2s_run_dir, "total_photon_source_intensities.txt")
    src_c1 = os.path.join(r2s_run_dir, "source_1.h5m")

    exp_e_bounds = os.path.join(r2s_run_dir, "exp_e_bounds")
    exp_t_p_src = os.path.join(r2s_run_dir,
                               "exp_total_photon_source_intensities.txt")
    exp_src_c1 = os.path.join(r2s_run_dir, "exp_source_1.h5m")

    # compare the results
    f4 = filecmp.cmp(e_bounds, exp_e_bounds)
    f5 = file_almost_same(t_p_src, exp_t_p_src)
    f6 = True
    # skip test if h5diff not exist
    if 'unstructured' in r2s_run_dir:
        ele_type = 'Tet4'
    else:
        ele_type = 'Hex8'
    is_h5diff = os.system('which h5diff')
    if is_h5diff == 0:
        # compare two h5 files
        command = ''.join([
            'h5diff --relative=1e-6 ', src_c1, ' ', exp_src_c1,
            ' /tstt/elements/', ele_type, '/tags/source_density',
            ' /tstt/elements/', ele_type, '/tags/source_density'
        ])
        diff_flag = os.system(command)
        # return value 0 if no difference, 1 if differences found, 2 if error
        f6 = True if diff_flag == 0 else False

    # remove test generated files
    os.remove(blank_mesh)
    os.remove(alara_inp)
    os.remove(e_bounds)
    os.remove(p_src)
    os.remove(t_p_src)
    os.remove(src_c1)
    os.remove(dst)

    assert_equal(f4, True)
    assert_equal(f5, True)
    assert_equal(f6, True)