예제 #1
0
def test_read_tracklist_into_different_surface():
    """We read in tracklists and compare with known values.
    We use a file with a single track for this test.
    """
    ssrname = "mcnp5_surfsrc.w"
    ssr1 = mcnp.SurfSrc(ssrname, "rb")
    try:
        ssr1.read_header()
    except:
        raise SkipTest
    ssr1.read_tracklist()

    ssr2 = mcnp.SurfSrc(ssrname_onetrack, "rb")
    ssr2.read_header()
    ssr2.read_tracklist()

    # Update ssr1 with ssr2's tracklist
    ssr1.update_tracklist(ssr2)

    for trackData in ssr1.tracklist:
        assert_equal(trackData.nps, 1)
        assert_almost_equal(trackData.bitarray, 8.000048e+06)
        assert_almost_equal(trackData.wgt, 0.99995639)
        assert_almost_equal(trackData.erg, 5.54203947)
        assert_almost_equal(trackData.tme, 0.17144023)
        assert_almost_equal(trackData.x, -8.05902e-02)
        assert_almost_equal(trackData.y, 3.122666098e+00)
        assert_almost_equal(trackData.z, 5.00000e+00)
        assert_almost_equal(trackData.u, -0.35133163)
        assert_almost_equal(trackData.v, 0.48465036)
        assert_almost_equal(trackData.cs, 0.80104937)
        assert_almost_equal(trackData.w, 0.80104937)
    return
예제 #2
0
파일: test_mcnp.py 프로젝트: rwcarlsen/pyne
 def test_compare(self):
     """Test the compare() method in the SurfSrc class
     Tricky to test... this just verifies that comparisons are done right.
     """
     ssrA = mcnp.SurfSrc(ssrname, 'rb')
     ssrB = mcnp.SurfSrc(ssrname, 'rb')
     ssrA.read_header()
     ssrB.read_header()
     self.assertTrue(ssrA.compare(ssrB))
     ssrA.close()
     ssrB.close()
예제 #3
0
def check_compare(ssrname):
    ssrA = mcnp.SurfSrc(ssrname, 'rb')
    ssrB = mcnp.SurfSrc(ssrname, 'rb')
    try:
        ssrA.read_header()
    except:
        raise SkipTest
    ssrB.read_header()
    assert_true(ssrA == ssrB)
    ssrA.close()
    ssrB.close()
예제 #4
0
파일: test_mcnp.py 프로젝트: rwcarlsen/pyne
    def test_put_header_block(self):
        """We copy the header block, write to new file, re-read, and compare.
        This tests that information is preserved correctly when written.
        """
        ssr = mcnp.SurfSrc(ssrname, "rb")
        ssw = mcnp.SurfSrc(sswname, "wb")
        ssr.read_header()

        # header record values
        ssw.kod    = ssr.kod
        ssw.ver    = ssr.ver
        ssw.loddat = ssr.loddat
        ssw.idtm   = ssr.idtm
        ssw.probid = ssr.probid
        ssw.aid    = ssr.aid
        ssw.knod   = ssr.knod
        # table 1 record values
        ssw.np1    = ssr.orignp1  # ssr.np1
        ssw.nrss   = ssr.nrss  
        ssw.ncrd   = ssr.ncrd
        ssw.njsw   = ssr.njsw
        ssw.niss   = ssr.niss
        # table 2 record values
        ssw.niwr   = ssr.niwr
        ssw.mipts  = ssr.mipts
        ssw.kjaq   = ssr.kjaq
        ssw.table2extra = ssr.table2extra
        # surface info record list
        ssw.surflist     = ssr.surflist
        # summary table record values
        ssw.summaryTable = ssr.summaryTable
        ssw.summaryExtra = ssr.summaryExtra

        ssw.put_header()
        ssw.put_table_1()
        ssw.put_table_2()
        ssw.put_surface_info()
        ssw.put_summary()
        ssw.close()

        sswr = mcnp.SurfSrc(sswname, "rb")
        sswr.read_header()
        
        self.assertEqual(ssr.print_header(), sswr.print_header())
        
        ssr.close()
        sswr.close()
        
        os.system("rm -f " + sswname)

        return
예제 #5
0
파일: test_mcnp.py 프로젝트: rwcarlsen/pyne
    def test_read_header_block(self):
        """Test the read_header() method in the SurfSrc class
        We compare the SurfSrc object variables with expected values from the
        file 'mcnp_surfsrc.w'.
        """
        ssr = mcnp.SurfSrc(ssrname, 'rb')
        ssr.read_header()

        # header record values
        self.assertEqual(ssr.kod   , "mcnp    ")
        self.assertEqual(ssr.ver   , "5    ")
        self.assertEqual(ssr.loddat, "01232009")
        self.assertEqual(ssr.idtm  , " 10/31/11 13:52:39 ")
        self.assertEqual(ssr.probid, " 10/31/11 13:52:35 ")
        self.assertEqual(ssr.aid   , "c Test deck with H20 cube, point n source, SSW of top surface interactions      ")
        self.assertEqual(ssr.knod  , 2)
        # table 1 record values
        self.assertEqual(ssr.np1   , 1000)
        self.assertEqual(ssr.nrss  , 173)
        self.assertEqual(ssr.ncrd  , 11)
        self.assertEqual(ssr.njsw  , 1)
        self.assertEqual(ssr.niss  , 173)
        # table 2 record values
        self.assertEqual(ssr.niwr  , 0)
        self.assertEqual(ssr.mipts , 3)
        self.assertEqual(ssr.kjaq  , 0)
예제 #6
0
파일: test_mcnp.py 프로젝트: rwcarlsen/pyne
    def test_read_tracklist(self):
        """We read in tracklists and compare with known values.
        We use a file with a single track for this test.
        """
        ssr = mcnp.SurfSrc(ssrname_onetrack, "rb")
        ssr.read_header()
        ssr.read_tracklist()

        # print "Length: " + str(len(ssr.tracklist))
        for trackData in ssr.tracklist:
            # Should only be one trackData in tracklist
            # trackData.record is skipped; contains the below components.
            # self.assertEqual(trackData.record  , 0) 
            self.assertEqual(trackData.nps     , 1) 
            self.assertAlmostEqual(trackData.bitarray, 8.000048e+06) 
            self.assertAlmostEqual(trackData.wgt     , 0.99995639) 
            self.assertAlmostEqual(trackData.erg     , 5.54203947) 
            self.assertAlmostEqual(trackData.tme     , 0.17144023) 
            self.assertAlmostEqual(trackData.x       , -8.05902e-02) 
            self.assertAlmostEqual(trackData.y       , 3.122666098e+00) 
            self.assertAlmostEqual(trackData.z       , 5.00000e+00) 
            self.assertAlmostEqual(trackData.u       , -0.35133163) 
            self.assertAlmostEqual(trackData.v       , 0.48465036) 
            self.assertAlmostEqual(trackData.cs      , 0.80104937) 
            self.assertAlmostEqual(trackData.w       , 0.80104937) 
        return
예제 #7
0
def test_print_tracklist():
    """Check SurfSrc.print_tracklist() against expected resulting string.
    We use a file with a single track for this test.
    """
    ssr = mcnp.SurfSrc(ssrname_onetrack, "rb")
    try:
        ssr.read_header()
    except struct.error:
        raise SkipTest
    ssr.read_tracklist()
    # If comparison output needs to be updated, uncomment the below
    #  and do: nosetests test_mcnp.py --nocapture
    try:
        observed = ssr.print_tracklist()
    except struct.error:
        raise SkipTest
    assert_equal(
        observed, 'Track Data\n       nps   BITARRAY        WGT        ERG'
        '        TME             X             Y             Z  '
        '        U          V     COSINE  |       W\n         '
        '1 8.00005e+06    0.99996      5.542    0.17144  '
        '-8.05902e-02   3.12267e+00   5.00000e+00   '
        '-0.35133    0.48465    0.80105  |    0.80105 \n')

    return
예제 #8
0
def test_print_header():
    """Check SurfSrc.print_header() against expected resulting string.
    We use a file with a single track for this test, but only use the
    header of this file.
    """
    ssr = mcnp.SurfSrc(ssrname_onetrack, "rb")
    try:
        ssr.read_header()
    except:
        raise SkipTest
    # If comparison output needs to be updated, uncomment the below
    #  and do: nosetests test_mcnp.py --nocapture
    #print ssr.print_header()
    assert_equal(
        ssr.print_header(), "Code: mcnp     (version: 5    ) [01232009]\n"
        "Problem info: ( 07/05/12 17:50:19 )"
        "  07/05/12 17:50:16 \n"
        "c Test deck with H20 cube, point n source,"
        " SSW of top surface interactions      \n"
        "Showing dump #2\n"
        "1 histories, 1 tracks, 11 record size, "
        "1 surfaces, 1 histories\n"
        "0 cells, source particle: 3, macrobody facet flag: 0\n"
        "Surface [6]: facet -1, type [4]"
        " with 1 parameters: ( [5.0])\n"
        "Summary Table: [0, 0, 1, 1, 1, 1,"
        " 0, 0, 0, 0, 0, 0, 0, 0, 0]")

    return
예제 #9
0
def check_put_header_block(ssrname, sswname):
    ssr = mcnp.SurfSrc(ssrname, "rb")
    ssw = mcnp.SurfSrc(sswname, "wb")
    try:
        ssr.read_header()
    except:
        raise SkipTest
    # header record values
    ssw.kod = ssr.kod
    ssw.ver = ssr.ver
    ssw.loddat = ssr.loddat
    ssw.idtm = ssr.idtm
    ssw.probid = ssr.probid
    ssw.aid = ssr.aid
    ssw.knod = ssr.knod
    # table 1 record values
    ssw.np1 = ssr.orignp1  # ssr.np1
    ssw.nrss = ssr.nrss
    ssw.ncrd = ssr.ncrd
    ssw.njsw = ssr.njsw
    ssw.niss = ssr.niss
    ssw.table1extra = ssr.table1extra
    # table 2 record values
    ssw.niwr = ssr.niwr
    ssw.mipts = ssr.mipts
    ssw.kjaq = ssr.kjaq
    ssw.table2extra = ssr.table2extra
    # surface info record list
    ssw.surflist = ssr.surflist
    # summary table record values
    ssw.summary_table = ssr.summary_table
    ssw.summary_extra = ssr.summary_extra

    ssw.write_header()
    ssw.close()

    sswr = mcnp.SurfSrc(sswname, "rb")
    sswr.read_header()

    assert_equal(ssr.print_header(), sswr.print_header())

    ssr.close()
    sswr.close()

    os.system("rm -f " + sswname)
예제 #10
0
파일: test_mcnp.py 프로젝트: rwcarlsen/pyne
    def test_print_tracklist(self):
        """Check SurfSrc.print_tracklist() against expected resulting string.
        We use a file with a single track for this test.
        """
        ssr = mcnp.SurfSrc(ssrname_onetrack, "rb")
        ssr.read_header()
        ssr.read_tracklist()
        # If comparison output needs to be updated, uncomment the below
        #  and do: nosetests test_mcnp.py --nocapture
        #print ssr.print_tracklist()
        self.assertEqual(ssr.print_tracklist(), 'Track Data\n       nps   BITARRAY        WGT        ERG        TME             X             Y             Z          U          V     COSINE  |       W\n         1 8.00005e+06    0.99996      5.542    0.17144  -8.05902e-02   3.12267e+00   5.00000e+00   -0.35133    0.48465    0.80105  |    0.80105 \n')

        return
예제 #11
0
def check_read_header_block(ssrname):
    if 'mcnp_surfsrc.w' in ssrname:
        ssr = mcnp.SurfSrc(ssrname, 'rb')

        try:
            ssr.read_header()
        except:
            raise SkipTest

        # header record values
        assert_equal(ssr.kod, "mcnp    ")
        assert_equal(ssr.ver, "5    ")
        assert_equal(ssr.loddat, "01232009")
        assert_equal(ssr.idtm, " 10/31/11 13:52:39 ")
        assert_equal(ssr.probid, " 10/31/11 13:52:35 ")
        assert_equal(
            ssr.aid, "c Test deck with H20 cube, point n source, "
            "SSW of top surface interactions      ")
        assert_equal(ssr.knod, 2)
        # table 1 record values
        assert_equal(ssr.np1, 1000)
        assert_equal(ssr.nrss, 173)
        assert_equal(ssr.ncrd, 11)
        assert_equal(ssr.njsw, 1)
        assert_equal(ssr.niss, 173)
        # table 2 record values
        assert_equal(ssr.niwr, 0)
        assert_equal(ssr.mipts, 3)
        assert_equal(ssr.kjaq, 0)

    elif 'mcnp6_surfsrc.w' in ssrname:
        ssr = mcnp.SurfSrc(ssrname, 'rb')
        try:
            ssr.read_header()
        except:
            raise SkipTest
        # header record values
        assert_equal(ssr.kod, "SF_00001")
        assert_equal(ssr.ver, "mcnp    6   ")
        assert_equal(ssr.loddat, " 05/08/13")
        assert_equal(ssr.idtm, " 11/18/13 17:50:49 ")
        assert_equal(ssr.probid, " 11/18/13 17:50:43 ")
        assert_equal(
            ssr.aid, "Simple MCNP Example that uses SSW"
            "                       "
            "                        ")
        assert_equal(ssr.knod, 2)
        # table 1 record values
        assert_equal(ssr.np1, 10000)
        assert_equal(ssr.nrss, 1710)
        assert_equal(ssr.ncrd, -11)
        #assert_equal(ssrA, ssrB)
        assert_equal(ssr.njsw, 1)
        assert_equal(ssr.niss, 1701)
        # table 2 record values
        assert_equal(ssr.niwr, 0)
        assert_equal(ssr.mipts, 37)
        assert_equal(ssr.kjaq, 0)

    elif 'mcnpx_surfsrc.w' in ssrname:
        ssr = mcnp.SurfSrc(ssrname, 'rb')
        try:
            ssr.read_header()
        except:
            raise SkipTest
        # header record values
        assert_equal(ssr.kod, "mcnpx   ")
        assert_equal(ssr.ver, "2.6.0")
        assert_equal(ssr.loddat, "Wed Apr 09 08:00:00 MST 2008")
        assert_equal(ssr.idtm, "  10/28/13 02:16:22")
        assert_equal(ssr.probid, "  10/28/13 02:16:16")
        assert_equal(
            ssr.aid, "Simple MCNP Example that uses SSW"
            "                                               ")
        assert_equal(ssr.knod, 2)
        # table 1 record values
        assert_equal(ssr.np1, 10000)
        assert_equal(ssr.nrss, 1658)
        assert_equal(ssr.ncrd, 11)
        assert_equal(ssr.njsw, 1)
        assert_equal(ssr.niss, 1652)
        # table 2 record values
        assert_equal(ssr.niwr, 0)
        assert_equal(ssr.mipts, 35)
        assert_equal(ssr.kjaq, 0)
예제 #12
0
def test_read_tracklist_into_different_surface_errors():
    """ 6 Exceptions that are handled by update_tracklist
    We iterate through each type of error and try match each exception
    We try to confirm each error caught by update_tracklist
    """
    ssrname = "mcnp5_surfsrc.w"
    ssr1 = mcnp.SurfSrc(ssrname, "rb")
    try:
        ssr1.read_header()
    except:
        raise SkipTest
    ssr1.read_tracklist()

    ssr2 = mcnp.SurfSrc(ssrname_onetrack, "rb")
    ssr2.read_header()
    ssr2.read_tracklist()

    # TypeError #1: Test with integer '1' in argument
    def wrong_type():
        ssr1.update_tracklist(1)

    assert_raises(TypeError, wrong_type)

    # AttributeError #2: If there is no header variables in surf_src argument
    ssrname = "mcnp5_surfsrc.w"
    ssr1 = mcnp.SurfSrc(ssrname, "rb")
    ssr1.read_header()

    ssr2 = mcnp.SurfSrc(ssrname_onetrack, "rb")

    def surf_src_arg_no_header():
        ssr1.update_tracklist(ssr2)

    assert_raises(AttributeError, surf_src_arg_no_header)

    # AttributeError #3: If there are no header variables in surf_src
    ssrname = "mcnp5_surfsrc.w"
    ssr1 = mcnp.SurfSrc(ssrname, "rb")

    ssr2 = mcnp.SurfSrc(ssrname_onetrack, "rb")
    ssr2.read_header()

    def surf_src_no_header():
        ssr1.update_tracklist(ssr2)

    assert_raises(AttributeError, surf_src_no_header)

    # AttributeError #4: If there is no tracklist in surf_src argument
    ssrname = "mcnp5_surfsrc.w"
    ssr1 = mcnp.SurfSrc(ssrname, "rb")
    ssr1.read_header()
    ssr1.read_tracklist()

    ssr2 = mcnp.SurfSrc(ssrname_onetrack, "rb")
    ssr2.read_header()

    def surf_src_arg_no_tracklist():
        ssr1.update_tracklist(ssr2)

    assert_raises(AttributeError, surf_src_arg_no_tracklist)

    # AttributeError #5: If there is no tracklist in surf_src
    ssrname = "mcnp5_surfsrc.w"
    ssr1 = mcnp.SurfSrc(ssrname, "rb")
    ssr1.read_header()

    ssr2 = mcnp.SurfSrc(ssrname_onetrack, "rb")
    ssr2.read_header()
    ssr2.read_tracklist()

    def surf_src_no_tracklist():
        ssr1.update_tracklist(ssr2)

    assert_raises(AttributeError, surf_src_no_tracklist)

    # ValueError #6: Update ssr1 with ssr1's tracklist
    ssrname = "mcnp5_surfsrc.w"
    ssr1 = mcnp.SurfSrc(ssrname, "rb")
    try:
        ssr1.read_header()
    except:
        raise SkipTest

    ssr1.read_tracklist()

    def update_with_self():
        ssr1.update_tracklist(ssr1)

    assert_raises(ValueError, update_with_self)

    return