コード例 #1
0
    def test_fortran_format(self):
        string = "-1.0-1"
        number = get_fortran_formatted_number(string)
        self.assertEqual(number, -1.e-1)

        string = "-1.0+1"
        number = get_fortran_formatted_number(string)
        self.assertEqual(number, -1.e1)

        string = "1.0+1"
        number = get_fortran_formatted_number(string)
        self.assertEqual(number, 1.e1)

        string = "15.0-100"
        number = get_fortran_formatted_number(string)
        self.assertEqual(number, 1.5e-99)

        string = "-15.0+39"
        number = get_fortran_formatted_number(string)
        self.assertEqual(number, -1.5e40)

        string = "-15.0+309"
        number = get_fortran_formatted_number(string)
        self.assertEqual(number, -1.5e310)

        string = "6.1000"
        number = get_fortran_formatted_number(string)
        self.assertEqual(number, 6.1000)

        string = "-6.1000"
        number = get_fortran_formatted_number(string)
        self.assertEqual(number, -6.1000)
コード例 #2
0
ファイル: MCNPMaterialCard.py プロジェクト: pshriwise/csg2csg
    def __process_string(self):
        # need to reset the dictionary
        # otherwise state seems to linger - weird
        self.composition_dictionary = {}

        mat_string = self.text_string
        mat_string = mat_string.replace("\n", "")

        # split string
        tokens = mat_string.split()

        if len(tokens) % 2 != 0:
            print("Material string not correctly processed")
            sys.exit(1)
        while len(tokens) != 0:
            nuclide = tokens[0].split(".")
            nucid = nuclide[0]
            try:
                xsid = nuclide[1]
            except:
                xsid = ""

            frac = get_fortran_formatted_number(tokens[1])
            tokens.pop(0)
            tokens.pop(0)
            self.composition_dictionary[nucid] = frac
            self.xsid_dictionary[nucid] = xsid
        return
コード例 #3
0
    def __interpret(self):

        string = self.text_string

        # look for mcnp cell specific keywords
        string = self.__detect_keywords(mcnp_cell_keywords, string)

        # this is to detect the presence of any importance
        # values only need one - used to indentify the
        # graveyard

        # expand the string first
        string = string.replace("(", " ( ")
        string = string.replace(")", " ) ")
        string = string.replace(":", " : ")
        string = string.replace("+", "")  # purge + signs

        # there can be mulitple comments per cell you sick sick people
        # why? is there any need? I mean really?!
        while '$' in string:
            pos = string.find('$')
            nl = string.find('\n', pos)
            string = string[:pos] + string[nl:]
            self.cell_comment += string[pos:nl]
        tokens = self.text_string.split()

        tokens = string.split()

        self.cell_id = int(tokens[0])
        material_number = int(tokens[1])
        if material_number > 0:
            self.cell_material_number = int(material_number)
            self.cell_density = get_fortran_formatted_number(tokens[2])
            self.cell_text_description = tokens[3:]
        else:
            self.cell_density = 0.
            self.cell_material_number = 0
            self.cell_text_description = tokens[2:]

        # now interpret the cell text description
        if not self.__is_sanitised():
            self.__sanitise()
        self.generalise()

        return