Пример #1
0
 def __init__(self, r=None, externalCodeInterface=None, fName=None):
     self.externalCodeInterface = externalCodeInterface
     self.eci = self.externalCodeInterface
     self.r = r
     self.cs = settings.getMasterCs()
     if fName:
         self.output = textProcessors.TextProcessor(fName)
     else:
         self.output = None
     self.fName = fName
Пример #2
0
    def read(self, fName):
        r"""
        Reads an assembly history file into memory.

        Parameters
        ----------
        fName : str
            The filename to read

        Creates a blockStack list where each entry is a dictionary of [param,ts]=val maps

        """

        f = textProcessors.TextProcessor(fName)
        timeSteps = map(int,
                        f.f.next().split())  # first line is timestep integers
        _timeYears = map(float,
                         f.f.next().split())  # second line is times in years

        # now there is a loop over all params
        blockStack = (
            []
        )  # will assign to block names once they are read in (at end of file)
        while True:
            # expect a line like: "key: burnup"
            line = f.fsearch("key:")
            paramName = line.split()[1]  # pylint: disable=no-member
            if paramName == "location":
                operation = str
            else:
                operation = float
            # expect values for each timestep on the next few lines
            for line in f.f:
                line = line.strip()
                # read arbitrary number of blocks
                if (
                        not line or "EOL bottom" in line
                ):  # detect axial info to(b/c we used to not have blank lines)
                    # end on blank line
                    break
                vals = map(operation, line.split())
                blockVals = {}
                for ts, val in zip(timeSteps, vals):
                    blockVals[paramName, ts] = val
                blockStack.append(blockVals)

            if paramName == "location":
                # flags the end of the params.
                break

        # skip the EOL axial information (for now)
        f.fsearch("Assembly info")

        assemblyInfoLine = next(f.f)
        assemblyInfo = assemblyInfoLine.split()
        self.assemName = assemblyInfo[0]
        if len(assemblyInfo) > 1:
            self.assemType = " ".join(assemblyInfo[1:]).lower()
        else:
            self.assemType = None

        blockTypes = []
        for line in f.f:
            match = re.search(r'"(.+)"\s(\S)\s(\S)', line)
            if match:
                blockTypes.append(match.group(1))
        f.f.close()

        self.blockStack = blockStack
Пример #3
0
 def setUp(self):
     self.tp = textProcessors.TextProcessor(
         os.path.join(TEST_ROOT, "geom.xml"))