Source code for armi.bookkeeping.visualization.tests.test_vis

# Copyright 2020 TerraPower, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test report visualization."""
import unittest

import numpy
from pyevtk.vtk import VtkTetra

from armi import settings
from armi.bookkeeping.db import Database3
from armi.bookkeeping.visualization import utils
from armi.bookkeeping.visualization import vtk
from armi.bookkeeping.visualization import xdmf
from armi.reactor import blocks
from armi.reactor import components
from armi.reactor.tests import test_reactors
from armi.utils.directoryChangers import TemporaryDirectoryChanger


[docs]class TestVtkMesh(unittest.TestCase): """Test the VtkMesh utility class."""
[docs] def test_testVtkMesh(self): mesh = utils.VtkMesh.empty() self.assertEqual(mesh.vertices.size, 0) self.assertEqual(mesh.vertices.shape, (0, 3)) self.assertEqual(mesh.connectivity.size, 0) self.assertEqual(mesh.offsets.size, 0) self.assertEqual(mesh.cellTypes.size, 0) verts = numpy.array( [[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0], [0.25, 0.25, 0.5]] ) conn = numpy.array([0, 1, 2, 3]) offsets = numpy.array([4]) cellTypes = numpy.array([VtkTetra.tid]) newMesh = utils.VtkMesh(verts, conn, offsets, cellTypes) mesh.append(newMesh) mesh.append(newMesh) self.assertEqual(mesh.vertices.size, 3 * 8) self.assertEqual(mesh.offsets.size, 2) self.assertEqual(mesh.connectivity.size, 8) self.assertEqual(mesh.cellTypes.size, 2) self.assertEqual(mesh.offsets[-1], 8) self.assertEqual(mesh.connectivity[-1], 7)
[docs]class TestVisDump(unittest.TestCase): """Test dumping a whole reactor and some specific block types.""" @classmethod def setUpClass(cls): caseSetting = settings.Settings() _, cls.r = test_reactors.loadTestReactor() cls.hexBlock = cls.r.core.getBlocks()[0] cls.cartesianBlock = blocks.CartesianBlock("TestCartesianBlock", caseSetting) cartesianComponent = components.HoledSquare( "duct", "UZr", Tinput=273.0, Thot=273.0, holeOD=68.0, widthOuter=12.5, mult=1.0, ) cls.cartesianBlock.add(cartesianComponent) cls.cartesianBlock.add( components.Circle( "clad", "HT9", Tinput=273.0, Thot=273.0, od=68.0, mult=169.0 ) )
[docs] def test_dumpReactorVtk(self): # This does a lot, and is hard to verify. at least make sure it doesn't crash with TemporaryDirectoryChanger(dumpOnException=False): dumper = vtk.VtkDumper("testVtk", inputName=None) with dumper: dumper.dumpState(self.r)
[docs] def test_dumpReactorXdmf(self): # This does a lot, and is hard to verify. at least make sure it doesn't crash with TemporaryDirectoryChanger(dumpOnException=False): db = Database3("testDatabase.h5", "w") with db: db.writeToDB(self.r) dumper = xdmf.XdmfDumper("testVtk", inputName="testDatabase.h5") with dumper: dumper.dumpState(self.r)
[docs] def test_hexMesh(self): mesh = utils.createBlockMesh(self.hexBlock) self.assertEqual(mesh.vertices.size, 12 * 3) self.assertEqual(mesh.cellTypes[0], 16)
[docs] def test_cartesianMesh(self): mesh = utils.createBlockMesh(self.cartesianBlock) self.assertEqual(mesh.vertices.size, 8 * 3) self.assertEqual(mesh.cellTypes[0], 12)