Beispiel #1
0
def test_write_tape5_irradiation():
    tape5 = StringIO()
    origen22.write_tape5_irradiation("IRP", 100, 0.550, xsfpy_nlb=[204, 205, 206],
                                     outfile=tape5,
                                     out_table_nes=(False, False, True),
                                     out_table_laf=(True,  False,  True),
                                     out_table_num=[5, 10])

    tape5.seek(0)
    observed = tape5.read()

    expected = ("  -1\n"
                "  -1\n"
                "  -1\n"
                "  CUT     5 1.000E-10 -1\n"
                "  RDA     Make sure thet the library identifier numbers match those in the"
                " TAPE9.INP file\n"
                "  LIB     0 1 2 3 204 205 206 9 3 0 4 0\n"
                "  OPTL    8 8 8 8 7 8 8 8 8 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8\n"
                "  OPTA    8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8\n"
                "  OPTF    8 8 8 8 7 8 8 8 8 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8\n"
                "  INP     1 -1  0  -1  4  4\n"
                "  RDA     All irradiation (IRF and IRP) cards must be between burnup (BUP) "
                "cards.\n"
                "  BUP\n"
                "  IRP     1.0000000000E+02  5.5000000000E-01   1   2   4  2\n"
                "  BUP\n"
                "  OUT     2  1 1 0\n"
                "  END\n")

    assert_equal(observed, expected)
Beispiel #2
0
def execute_origen(xs_tape9, time, nuclide, phi, origen, decay_tape9):
    xs_tape9 = xs_tape9
    if not os.path.isabs(xs_tape9):
        xs_tape9 = os.path.join(LIBS_DIR, xs_tape9)

    parsed_xs_tape9 = parse_tape9(xs_tape9)
    parsed_decay_tape9 = parse_tape9(decay_tape9)

    merged_tape9 = merge_tape9([parsed_decay_tape9, parsed_xs_tape9])

    # Can set outfile to change directory, but the file name needs to be
    # TAPE9.INP.
    write_tape9(merged_tape9)

    decay_nlb, xsfpy_nlb = nlbs(parsed_xs_tape9)

    # Can set outfile, but the file name should be called TAPE5.INP.
    write_tape5_irradiation("IRF", time/(60*60*24), phi,
        xsfpy_nlb=xsfpy_nlb, cut_off=0, out_table_num=[4, 5],
        out_table_nes=[True, False, False])

    M = from_atom_frac({nuclide: 1}, mass=1, atoms_per_molecule=1)

    write_tape4(M)

    # Make pyne use naive atomic mass numbers to match ORIGEN
    for i in pyne.data.atomic_mass_map:
        pyne.data.atomic_mass_map[i] = float(pyne.nucname.anum(i))

    origen_time, data = time_func(run_origen, origen)

    logger.info("ORIGEN runtime: %s", origen_time)
    return origen_time, data
Beispiel #3
0
    def _make_origen_input(self, transmute_time, phi_tot, mat):
        """Make ORIGEN input files for a given state.

        Parameters
        ----------
        transmute_time : float
            The time, in days, to run the transmutation for.
        phi_tot: float
            Total neutron flux.
        mat : pyne.material.Material
            The fuel material to transmute.
        Returns
        -------
        None
        """
        # may need to filter tape4 for Bad Nuclides
        # if sum(mat.comp.values()) > 1:
        for nuc in mat.comp:
            if mat.comp[nuc] < self.rc.track_nuc_threshold:
                del mat.comp[nuc]
        origen22.write_tape4(mat)
        origen22.write_tape5_irradiation("IRF",
                                         transmute_time,
                                         phi_tot,
                                         xsfpy_nlb=(219, 220, 221),
                                         cut_off=self.rc.track_nuc_threshold)
        origen22.write_tape9(self.tape9)
Beispiel #4
0
def test_write_tape5_irradiation():
    tape5 = StringIO()
    origen22.write_tape5_irradiation("IRP",
                                     100,
                                     0.550,
                                     xsfpy_nlb=[204, 205, 206],
                                     outfile=tape5,
                                     out_table_nes=(False, False, True),
                                     out_table_laf=(True, False, True),
                                     out_table_num=[5, 10])

    tape5.seek(0)
    observed = tape5.read()

    expected = (
        "  -1\n"
        "  -1\n"
        "  -1\n"
        "  CUT     5 1.000E-10 -1\n"
        "  RDA     Make sure thet the library identifier numbers match those in the TAPE9.INP file\n"
        "  LIB     0 1 2 3 204 205 206 9 3 0 4 0\n"
        "  OPTL    8 8 8 8 7 8 8 8 8 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8\n"
        "  OPTA    8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8\n"
        "  OPTF    8 8 8 8 7 8 8 8 8 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8\n"
        "  INP     1 -1  0  -1  4  4\n"
        "  RDA     All irradiation (IRF and IRP) cards must be between burnup (BUP) cards.\n"
        "  BUP\n"
        "  IRP     1.0000000000E+02  5.5000000000E-01   1   2   4  2\n"
        "  BUP\n"
        "  OUT     2  1 1 0\n"
        "  END\n")

    assert_equal(observed, expected)
Beispiel #5
0
    def _make_origen_input(self, transmute_time, phi_tot, mat):
        """Make ORIGEN input files for a given state.

        Parameters
        ----------
        state : namedtuple (State)
            A namedtuple containing the state parameters.
        transmute_time : float
            The time, in days, to run the transmutation for.
        phi_tot: float
            Total neutron flux.
        mat : pyne.material.Material
            The fuel material to transmute.
        Returns
        -------
        None
        """
        # may need to filter tape4 for Bad Nuclides
        # if sum(mat.comp.values()) > 1:
        origen22.write_tape4(mat)
        origen22.write_tape5_irradiation("IRF",
                                         transmute_time,
                                         phi_tot,
                                         xsfpy_nlb=(219, 220, 221),
                                         cut_off=1e-300)
        origen22.write_tape9(self.tape9)
Beispiel #6
0
def test_write_inf_tape5_irradiation():
    tape5 = StringIO()
    with assert_raises(ValueError) as context:
        origen22.write_tape5_irradiation("IRP", 100, np.inf, xsfpy_nlb=[204, 205, 206],
                                         outfile=tape5,
                                         out_table_nes=(False, False, True),
                                         out_table_laf=(True,  False,  True),
                                         out_table_num=[5, 10])
    ex = context.exception
    assert_equal(ex.args[0], "Irradiation value is infinite.")
Beispiel #7
0
def test_write_inf_tape5_irradiation():
    tape5 = StringIO()
    with assert_raises(ValueError) as context:
        origen22.write_tape5_irradiation("IRP",
                                         100,
                                         np.inf,
                                         xsfpy_nlb=[204, 205, 206],
                                         outfile=tape5,
                                         out_table_nes=(False, False, True),
                                         out_table_laf=(True, False, True),
                                         out_table_num=[5, 10])
    ex = context.exception
    assert_equal(ex.args[0], "Irradiation value is infinite.")
    def calc_transmutation(self):
        """Use ORIGEN as a backend to perform the transmutation calculation."""
        K = self.K
        s = self.bt_s
        T_it = self.T_it

        # Make origen cross section library
        t9 = origen22.merge_tape9([self._xs, self._tape9])
        origen22.write_tape9(t9)

        # Make input mass stream
        mat = Material({iso: 1E3 * T_it[iso][s] for iso in K})
        origen22.write_tape4(mat)

        # Make origen input file
        irr_type = 'IRP'
        irr_time = self.burn_times[s+1] - self.burn_times[s]
        irr_value = self.specific_power
        t5kw = {
            'decay_nlb': sorted(nlb for nlb in t9.keys() if t9[nlb]['_type'] == 'decay')[:3],
            'xsfpy_nlb': sorted(nlb for nlb in t9.keys() if t9[nlb]['_type'] == 'xsfpy')[:3],
            'out_table_nes': (True, False, False),
            'cut_off': 1E-300, 
            'out_table_num': [5],
            }
        origen22.write_tape5_irradiation(irr_type, irr_time, irr_value, **t5kw)

        # Run origen
        rtn = subprocess.check_call("o2_therm_linux.exe", shell=True)

        # Parse origen output 
        res = origen22.parse_tape6()
        #outvec = {key: sum([v[-1] for v in value]) * 1E-3 for key, value in res['table_5']['nuclide']['data'].items() if (key in K) and not np.isnan(value).any()}
        outvec = res['materials'][-1].comp
        nullvec = {k: 0.0 for k in K if k not in outvec}
        outvec.update(nullvec)

        # update the transmutation matrix
        sp1 = s + 1
        for nuc in K:
            T_it[nuc][sp1] = outvec[nuc]
        self.T_it = T_it

        # update the burnup
        BU_t = self.BU_t
        deltaBU = irr_time * irr_value
        BU_t[sp1] = BU_t[s] + deltaBU
        self.BU_t = BU_t
        print "   BU_t = {0}".format(BU_t[sp1])
Beispiel #9
0
    def transmute(self, x, t=None, phi=None, tol=None, cwd=None, xscache=None, 
                  o2exe=None, *args, **kwargs):
        """Transmutes a material into its daughters.

        Parameters
        ----------
        x : Material or similar
            Input material for transmutation.
        t : float
            Transmutations time [sec].
        phi : float or array of floats
            Neutron flux vector [n/cm^2/sec].  Currently this must either be 
            a scalar or match the group structure of EAF.
        tol : float
            Tolerance level for chain truncation.
        cwd : str, optional
            Current working directory for origen runs. Defaults to this dir.
        xscache : XSCache, optional
            A cross section cache to generate cross sections with.
        o2exe : str, optional
            Name or path to ORIGEN 2.2 executable.

        Returns
        -------
        y : Material
            The output material post-transmutation.

        """
        if not isinstance(x, Material):
            x = Material(x)
        if t is not None:
            self.t = t
        if phi is not None:
            self.phi = phi
        if tol is not None:
            self.tol = tol
        if cwd is not None:
            self.cwd = os.path.abspath(cwd)
        if xscache is not None:
            self.xscache = xscache
        if o2exe is not None:
            self.o2exe = o2exe

        # prepare new tape9
        nucs = set(x.comp.keys())
        base_tape9 = self.base_tape9
        decay_nlb, xsfpy_nlb = origen22.nlbs(base_tape9)
        new_tape9 = origen22.xslibs(nucs=nucs, xscache=self.xscache, nlb=xsfpy_nlb)
        t9 = origen22.merge_tape9([new_tape9, base_tape9])

        # write out files
        origen22.write_tape4(x, outfile=os.path.join(self.cwd, 'TAPE4.INP'))
        origen22.write_tape5_irradiation('IRF', self.t/86400.0, self.xscache['phi_g'][0], 
            outfile=os.path.join(self.cwd, 'TAPE5.INP'), decay_nlb=decay_nlb, 
            xsfpy_nlb=xsfpy_nlb, cut_off=self.tol)
        origen22.write_tape9(t9, outfile=os.path.join(self.cwd, 'TAPE9.INP'))

        # run origen & get results
        f = tempfile.NamedTemporaryFile()
        try:
            subprocess.check_call([self.o2exe], cwd=self.cwd, stdout=f, stderr=f)
        except subprocess.CalledProcessError:
            f.seek(0)
            print("ORIGEN output:\n\n{0}".format(f.read()))
            raise
        finally:
            f.close()
        t6 = origen22.parse_tape6(tape6=os.path.join(self.cwd, 'TAPE6.OUT'))
        y = t6['materials'][-1]
        return y
Beispiel #10
0
    def transmute(self,
                  x,
                  t=None,
                  phi=None,
                  tol=None,
                  cwd=None,
                  xscache=None,
                  o2exe=None,
                  *args,
                  **kwargs):
        """Transmutes a material into its daughters.

        Parameters
        ----------
        x : Material or similar
            Input material for transmutation.
        t : float
            Transmutations time [sec].
        phi : float or array of floats
            Neutron flux vector [n/cm^2/sec].  Currently this must either be 
            a scalar or match the group structure of EAF.
        tol : float
            Tolerance level for chain truncation.
        cwd : str, optional
            Current working directory for origen runs. Defaults to this dir.
        xscache : XSCache, optional
            A cross section cache to generate cross sections with.
        o2exe : str, optional
            Name or path to ORIGEN 2.2 executable.

        Returns
        -------
        y : Material
            The output material post-transmutation.

        """
        if not isinstance(x, Material):
            x = Material(x)
        if t is not None:
            self.t = t
        if phi is not None:
            self.phi = phi
        if tol is not None:
            self.tol = tol
        if cwd is not None:
            self.cwd = os.path.abspath(cwd)
        if xscache is not None:
            self.xscache = xscache
        if o2exe is not None:
            self.o2exe = o2exe

        # prepare new tape9
        nucs = set(x.comp.keys())
        base_tape9 = self.base_tape9
        decay_nlb, xsfpy_nlb = origen22.nlbs(base_tape9)
        new_tape9 = origen22.xslibs(nucs=nucs,
                                    xscache=self.xscache,
                                    nlb=xsfpy_nlb)
        t9 = origen22.merge_tape9([new_tape9, base_tape9])

        # write out files
        origen22.write_tape4(x, outfile=os.path.join(self.cwd, 'TAPE4.INP'))
        origen22.write_tape5_irradiation('IRF',
                                         self.t / 86400.0,
                                         self.xscache['phi_g'][0],
                                         outfile=os.path.join(
                                             self.cwd, 'TAPE5.INP'),
                                         decay_nlb=decay_nlb,
                                         xsfpy_nlb=xsfpy_nlb,
                                         cut_off=self.tol)
        origen22.write_tape9(t9, outfile=os.path.join(self.cwd, 'TAPE9.INP'))

        # run origen & get results
        f = tempfile.NamedTemporaryFile()
        try:
            subprocess.check_call([self.o2exe],
                                  cwd=self.cwd,
                                  stdout=f,
                                  stderr=f)
        except subprocess.CalledProcessError:
            f.seek(0)
            print("ORIGEN output:\n\n{0}".format(f.read()))
            raise
        finally:
            f.close()
        t6 = origen22.parse_tape6(tape6=os.path.join(self.cwd, 'TAPE6.OUT'))
        y = t6['materials'][-1]
        return y
Beispiel #11
0

# 1 kg of water
water = Material()
water.from_atom_frac({'H1': 2.0, 'O16': 1.0})
water.mass = 1E3

# Make a tape4 file for water
origen22.write_tape4(water)

# Make a tape 5 for this calculation
#   * Just output the concentration tables
#   * The cross-section library numbers must 
#     the library / deck numbers in tape9 
origen22.write_tape5_irradiation("IRF", 1000.0, 4E14, 
                                 xsfpy_nlb=(381, 382, 383), 
                                 out_table_num=[5])

# Grab a base tape9 from which we will overlay new values
# This must be supplied by the user
base_tape9 = origen22.parse_tape9("BASE_TAPE9.INP")

base_h1_xs = base_tape9[381]['sigma_gamma'][10010]

# Init a dumb overlay tape9
overlay_tape9 = {381: {'_type': 'xsfpy', 
                       '_subtype': 'activation_products', 
                       'sigma_gamma': {10010: base_h1_xs}, 
                       }
                }
Beispiel #12
0
# 1 kg of water
water = Material()
water.from_atom_frac({'H1': 2.0, 'O16': 1.0})
water.mass = 1E3

# Make a tape4 file for water
origen22.write_tape4(water)

# Make a tape 5 for this calculation
#   * Just output the concentration tables
#   * The cross-section library numbers must
#     the library / deck numbers in tape9
origen22.write_tape5_irradiation("IRF",
                                 1000.0,
                                 4E14,
                                 xsfpy_nlb=(381, 382, 383),
                                 out_table_num=[5])

# Grab a base tape9 from which we will overlay new values
# This must be supplied by the user
base_tape9 = origen22.parse_tape9("BASE_TAPE9.INP")

base_h1_xs = base_tape9[381]['sigma_gamma'][10010]

# Init a dumb overlay tape9
overlay_tape9 = {
    381: {
        '_type': 'xsfpy',
        '_subtype': 'activation_products',
        'sigma_gamma': {