Skip to content

Add support for photon production XS from ACE files #15

@dodu94

Description

@dodu94

Hi, it would be nice to add photon production XS parsing. I recently had to systematically plot these XS in a V&V campaign for a new release of D1S nuclear data libraries and I noticed that the part that should parse photon XS is under TODO.

I ended up writing a very small parser based on the ace object of this repo in order to complete my task and I wanted to try and implement it back here. Unfortunately it seems that to install the package in editable mode and to work on it I need C++ compiler which for IT restrictions reasons I cannot install.

I figured that reporting here the small code would still be useful (at least the pure parsing part) in case someone else would like to complete the job. I only dealt with MF 13 derived cross sections and not MF 12 or MF 16 ones.

Here is the code:

class ParsedAce:
    def __init__(self, file: os.PathLike | str) -> None:
        self._ace = ace.get_table(file)
        self.energy_grid = self._parse_energy_grid()
        self.neutron_MT, self.gamma_MT = self._parse_MTs()
        self.photon_xs = self._parse_photon_xs()

    def get_photon_MTs(self) -> dict:
        """get the photon MTs for all neutron MTs

        Parameters
        ----------
        neutron_MT : int
            _description_

        Returns
        -------
        dict
            _description_
        """

        mts_dict = {}
        for arb_mt in self.gamma_MT:
            num = int(str(arb_mt)[-3:])
            mt = int(str(arb_mt)[:-3])
            if mt in mts_dict:
                mts_dict[mt].append(num)
            else:
                mts_dict[mt] = [num]

        return mts_dict

    def _parse_energy_grid(self) -> np.ndarray:
        """parse the global energy grid from the ACE table"""
        S_ESZ = int(self._ace.jxs[1])
        NE_ESZ = int(self._ace.nxs[3])
        return self._ace.xss[S_ESZ : S_ESZ + NE_ESZ]

    def _parse_MTs(self) -> tuple[np.ndarray, np.ndarray]:
        """parse the MTs for neutron and gamma reactions"""
        MTR_LMT = self._ace.jxs[3]
        MTR_NMT = self._ace.nxs[4]
        MTRP_LMT = self._ace.jxs[13]
        MTRP_NMT = self._ace.nxs[6]
        neutron_MT = self._ace.xss[MTR_LMT : MTR_LMT + MTR_NMT].astype(int)
        gamma_MT = self._ace.xss[MTRP_LMT : MTRP_LMT + MTRP_NMT].astype(int)
        return neutron_MT, gamma_MT

    def _parse_photon_xs(self) -> dict:
        """parse the photon cross section data"""
        LXS = self._ace.jxs[14]
        xs_data = {}
        for i, mt in enumerate(self.gamma_MT):
            LOCA = self._ace.xss[LXS + i]
            index = int(self._ace.jxs[15] + LOCA - 1)
            MF = self._ace.xss[index]

            xs = []
            e = []
            if MF == 12 or MF == 16:
                pass  # TODO
            elif MF == 13:
                IE = int(self._ace.xss[index + 1])  # energy grid index
                NE = int(self._ace.xss[index + 2])  # number of consecutive entries
                xs = self._ace.xss[(index + 3) : (index + 3 + NE)]
                e = self.energy_grid[IE - 1 : IE - 1 + NE]
            else:
                raise ValueError(f"MF {MF} not supported")

            xs_data[mt] = {"MT": mt, "energy": e, "xs": xs, "MF": MF}

        return xs_data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions