コード例 #1
0
    def test_hexWithHoles(self):
        """Read 1/3 core flats-up maps with holes."""
        asciimap = asciimaps.AsciiMapHexThirdFlatsUp()
        with io.StringIO() as stream:
            stream.write(HEX_THIRD_MAP_WITH_HOLES)
            stream.seek(0)
            asciimap.readAscii(stream.read())

        with io.StringIO() as stream:
            asciimap.writeAscii(stream)
            stream.seek(0)
            output = stream.read()
            self.assertEqual(output, HEX_THIRD_MAP_WITH_HOLES)

        self.assertEqual(asciimap[1, 1], asciimaps.PLACEHOLDER)
        self.assertEqual(asciimap[5, 0], "TG")
        with self.assertRaises(KeyError):
            asciimap[10, 0]  # pylint: disable=pointless-statement

        # also test writing from pure data (vs. reading) gives the exact same map :o
        with io.StringIO() as stream:
            asciimap2 = asciimaps.AsciiMapHexThirdFlatsUp()
            asciimap2.asciiLabelByIndices = asciimap.asciiLabelByIndices
            asciimap2.gridContentsToAscii()
            asciimap2.writeAscii(stream)
            stream.seek(0)
            output = stream.read()
            self.assertEqual(output, HEX_THIRD_MAP_WITH_HOLES)
コード例 #2
0
    def test_troublesomeHexThird(self):
        asciimap = asciimaps.AsciiMapHexThirdFlatsUp()
        with io.StringIO() as stream:
            stream.write(HEX_THIRD_MAP_2)
            stream.seek(0)
            asciimap.readAscii(stream.read())

        with io.StringIO() as stream:
            asciimap.writeAscii(stream)
            stream.seek(0)
            output = stream.read()
            self.assertEqual(output, HEX_THIRD_MAP_2)

        self.assertEqual(asciimap[5, 0], "TG")
コード例 #3
0
    def _writeAsciiMap(self):
        """Generate an ASCII map representation.

        Warning
        -------
        This only works for HexGrid.
        """
        lattice = {}
        for ring, pos in sorted(list(self.assemTypeByIndices)):
            specifier = self.assemTypeByIndices[(ring, pos)]
            i, j = grids.HexGrid.getIndicesFromRingAndPos(ring, pos)
            lattice[i, j] = specifier

        geomMap = asciimaps.AsciiMapHexThirdFlatsUp()
        geomMap.asciiLabelByIndices = lattice
        geomMap.gridContentsToAscii()
        geomMap.writeAscii(sys.stdout)
コード例 #4
0
ファイル: systemLayoutInput.py プロジェクト: tylerHanf/armi
 def _read_yaml_lattice(self, system):
     """Read a ascii map string into this object."""
     mapTxt = system[INP_LATTICE]
     if self.geomType == geometry.HEX and geometry.THIRD_CORE in self.symmetry:
         asciimap = asciimaps.AsciiMapHexThirdFlatsUp()
         asciimap.readAscii(mapTxt)
         for (i, j), spec in asciimap.items():
             if spec == "-":
                 # skip whitespace placeholders
                 continue
             ring, pos = grids.HexGrid.indicesToRingPos(i, j)
             self.assemTypeByIndices[(ring, pos)] = spec
             self.maxRings = max(ring, self.maxRings)
     else:
         raise ValueError(
             f"ASCII map reading from geom/symmetry: {self.geomType}/"
             f"{self.symmetry} not supported.")
コード例 #5
0
    def test_hexWithEmptyRow(self):
        """Read 1/3 core flats-up maps with one entirely empty row."""
        asciimap = asciimaps.AsciiMapHexThirdFlatsUp()
        with io.StringIO() as stream:
            stream.write(HEX_THIRD_MAP_WITH_EMPTY_ROW)
            stream.seek(0)
            asciimap.readAscii(stream.read())

        with io.StringIO() as stream:
            asciimap.writeAscii(stream)
            stream.seek(0)
            output = stream.read()
            self.assertEqual(output, HEX_THIRD_MAP_WITH_EMPTY_ROW)

        self.assertEqual(asciimap[1, 1], asciimaps.PLACEHOLDER)
        self.assertEqual(asciimap[6, 0], asciimaps.PLACEHOLDER)
        self.assertEqual(asciimap[5, 0], "TG")
        with self.assertRaises(KeyError):
            asciimap[10, 0]  # pylint: disable=pointless-statement
コード例 #6
0
    def test_hexThird(self):
        """Read 1/3 core flats-up maps."""
        asciimap = asciimaps.AsciiMapHexThirdFlatsUp()
        with io.StringIO() as stream:
            stream.write(HEX_THIRD_MAP)
            stream.seek(0)
            asciimap.readAscii(stream.read())

        with io.StringIO() as stream:
            asciimap.writeAscii(stream)
            stream.seek(0)
            output = stream.read()
            self.assertEqual(output, HEX_THIRD_MAP)

        self.assertEqual(asciimap[7, 0], "2")
        self.assertEqual(asciimap[8, 0], "3")
        self.assertEqual(asciimap[8, -4], "2")
        self.assertEqual(asciimap[0, 8], "3")
        self.assertEqual(asciimap[0, 0], "1")
        with self.assertRaises(KeyError):
            asciimap[10, 0]  # pylint: disable=pointless-statement