OpenMC/tests/unit_tests/mesh_to_vtk/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
3.1 KiB
Python
Raw Permalink Normal View History

import difflib
Adding more mesh interrogation options for the libmesh Finishing methods for connectivity and coordinates. Writing vertices and connectivity to statepoint file Loading vertices and connectivity from statepoint. Correcting string repr Correcting connectivity length Adding method to write the mesh elements to VTK with data applied. Updating hdf5 output to include element types Adding support for hex elements when writing unstructured meshes to VTK Adding simple check for VTK writing if the module is present Removing centroids from the statepoint file and Python UM class Updating test check for vtk Adding warning for skipped elements. Correcting element type Adding warning for skipped elements. Using an enum to indicate element types for readability Updating to element types on the Python side as well Handling integer data applied to VTK files. Doc updates for Python API UM class Incrementing statepoint version number Refactor of unstructured mesh tests to extract model Updating inputs for floating point surface coefficients Adding test for hexes and refactoring comparison funcs Updating reference mesh files Adding reference file for the hexes test case Passing test for hex mesh Adding inputs for the hexes test case. Adding hex test meshes. Skipping hex mesh test if not built with libmesh Adding small VTK write tests for unstructured mesh. Allowing file path to be a pathlib path. Adding skips if libmesh or dagmc not enabled Adding a few comments to test file Changing where conversion to str happens for mesh filename. Setting output to false. Removing VTK check from unstructured mesh regression test Removnig VTK test files for regression test -- too large Adding __init__.py file for pytest
2022-05-31 08:33:43 -05:00
import filecmp
import numpy as np
from pathlib import Path
Adding more mesh interrogation options for the libmesh Finishing methods for connectivity and coordinates. Writing vertices and connectivity to statepoint file Loading vertices and connectivity from statepoint. Correcting string repr Correcting connectivity length Adding method to write the mesh elements to VTK with data applied. Updating hdf5 output to include element types Adding support for hex elements when writing unstructured meshes to VTK Adding simple check for VTK writing if the module is present Removing centroids from the statepoint file and Python UM class Updating test check for vtk Adding warning for skipped elements. Correcting element type Adding warning for skipped elements. Using an enum to indicate element types for readability Updating to element types on the Python side as well Handling integer data applied to VTK files. Doc updates for Python API UM class Incrementing statepoint version number Refactor of unstructured mesh tests to extract model Updating inputs for floating point surface coefficients Adding test for hexes and refactoring comparison funcs Updating reference mesh files Adding reference file for the hexes test case Passing test for hex mesh Adding inputs for the hexes test case. Adding hex test meshes. Skipping hex mesh test if not built with libmesh Adding small VTK write tests for unstructured mesh. Allowing file path to be a pathlib path. Adding skips if libmesh or dagmc not enabled Adding a few comments to test file Changing where conversion to str happens for mesh filename. Setting output to false. Removing VTK check from unstructured mesh regression test Removnig VTK test files for regression test -- too large Adding __init__.py file for pytest
2022-05-31 08:33:43 -05:00
import openmc
import pytest
from tests.regression_tests import config
Adding more mesh interrogation options for the libmesh Finishing methods for connectivity and coordinates. Writing vertices and connectivity to statepoint file Loading vertices and connectivity from statepoint. Correcting string repr Correcting connectivity length Adding method to write the mesh elements to VTK with data applied. Updating hdf5 output to include element types Adding support for hex elements when writing unstructured meshes to VTK Adding simple check for VTK writing if the module is present Removing centroids from the statepoint file and Python UM class Updating test check for vtk Adding warning for skipped elements. Correcting element type Adding warning for skipped elements. Using an enum to indicate element types for readability Updating to element types on the Python side as well Handling integer data applied to VTK files. Doc updates for Python API UM class Incrementing statepoint version number Refactor of unstructured mesh tests to extract model Updating inputs for floating point surface coefficients Adding test for hexes and refactoring comparison funcs Updating reference mesh files Adding reference file for the hexes test case Passing test for hex mesh Adding inputs for the hexes test case. Adding hex test meshes. Skipping hex mesh test if not built with libmesh Adding small VTK write tests for unstructured mesh. Allowing file path to be a pathlib path. Adding skips if libmesh or dagmc not enabled Adding a few comments to test file Changing where conversion to str happens for mesh filename. Setting output to false. Removing VTK check from unstructured mesh regression test Removnig VTK test files for regression test -- too large Adding __init__.py file for pytest
2022-05-31 08:33:43 -05:00
pytest.importorskip('vtk')
Adding more mesh interrogation options for the libmesh Finishing methods for connectivity and coordinates. Writing vertices and connectivity to statepoint file Loading vertices and connectivity from statepoint. Correcting string repr Correcting connectivity length Adding method to write the mesh elements to VTK with data applied. Updating hdf5 output to include element types Adding support for hex elements when writing unstructured meshes to VTK Adding simple check for VTK writing if the module is present Removing centroids from the statepoint file and Python UM class Updating test check for vtk Adding warning for skipped elements. Correcting element type Adding warning for skipped elements. Using an enum to indicate element types for readability Updating to element types on the Python side as well Handling integer data applied to VTK files. Doc updates for Python API UM class Incrementing statepoint version number Refactor of unstructured mesh tests to extract model Updating inputs for floating point surface coefficients Adding test for hexes and refactoring comparison funcs Updating reference mesh files Adding reference file for the hexes test case Passing test for hex mesh Adding inputs for the hexes test case. Adding hex test meshes. Skipping hex mesh test if not built with libmesh Adding small VTK write tests for unstructured mesh. Allowing file path to be a pathlib path. Adding skips if libmesh or dagmc not enabled Adding a few comments to test file Changing where conversion to str happens for mesh filename. Setting output to false. Removing VTK check from unstructured mesh regression test Removnig VTK test files for regression test -- too large Adding __init__.py file for pytest
2022-05-31 08:33:43 -05:00
def full_path(f):
return Path(__file__).parent.absolute() / f
def diff_file(file1, file2):
with open(file1) as fh:
f1_text = fh.readlines()
with open(file2) as fh:
f2_text = fh.readlines()
diff_lines = difflib.unified_diff(f1_text, f2_text)
return ''.join(diff_lines)
# test meshes
reg_mesh = openmc.RegularMesh()
reg_mesh.lower_left = (0, 0, 0)
reg_mesh.upper_right = (20, 50, 50)
reg_mesh.dimension = (10, 20, 30)
rect_mesh = openmc.RectilinearMesh()
rect_mesh.x_grid = np.linspace(0, 10, 5)
rect_mesh.y_grid = np.geomspace(5., 20., 10)
rect_mesh.z_grid = np.linspace(1, 100, 20)
cyl_mesh = openmc.CylindricalMesh(
origin=(10, 10, -10),
r_grid=np.linspace(0, 5, 5),
phi_grid=np.linspace(0, 2 * np.pi, 4),
z_grid=np.linspace(0, 2, 4),
)
sphere_mesh = openmc.SphericalMesh(
origin=(10, 10, -10),
r_grid=np.linspace(0, 5, 3),
theta_grid=np.linspace(0, 0.5 * np.pi, 4),
phi_grid=np.linspace(0, 2*np.pi, 8),
)
def mesh_data(mesh_dims):
data = 100 * np.arange(np.prod(mesh_dims), dtype=float)
# data is returned reshaped with order 'F' to ensure that
# the resulting data is interpreted correctly by the
# write_data_to_vtk method
return data.reshape(*mesh_dims, order='F')
test_data = ((reg_mesh, False, 'regular'),
(rect_mesh, False, 'rectilinear'),
(cyl_mesh, False, 'cylindrical-linear'),
(cyl_mesh, True, 'cylindrical-curvilinear'),
(sphere_mesh, False, 'spherical-linear'),
(sphere_mesh, True, 'spherical-curvilinear'))
@pytest.mark.parametrize('mesh_params',
test_data,
ids=lambda params: params[2])
def test_mesh_write_vtk(mesh_params, run_in_tmpdir):
mesh, curvilinear, filename = mesh_params
test_data = full_path(filename + ".vtk")
kwargs = {}
if curvilinear:
kwargs['curvilinear'] = curvilinear
# set output filename based on test configuration
filename = test_data if config['update'] else filename + "-actual.vtk"
# write the mesh file and compare to the expected version
mesh.write_data_to_vtk(filename, **kwargs)
try:
assert filecmp.cmp(test_data, filename)
except AssertionError as e:
diff = diff_file(test_data, filename)
raise AssertionError(diff) from e
# check data writing
def test_mesh_write_vtk_data(run_in_tmpdir):
data = {'ascending_data': mesh_data(cyl_mesh.dimension)}
filename_expected = full_path('cyl-data.vtk')
filename_actual = full_path('cyl-data-actual.vtk')
# update the test file if requested
filename = filename_expected if config['update'] else filename_actual
cyl_mesh.write_data_to_vtk(filename, datasets=data, volume_normalization=False)
try:
assert filecmp.cmp(filename, filename_expected)
except AssertionError as e:
diff = diff_file(filename_expected, filename)
raise AssertionError(diff) from e
Adding more mesh interrogation options for the libmesh Finishing methods for connectivity and coordinates. Writing vertices and connectivity to statepoint file Loading vertices and connectivity from statepoint. Correcting string repr Correcting connectivity length Adding method to write the mesh elements to VTK with data applied. Updating hdf5 output to include element types Adding support for hex elements when writing unstructured meshes to VTK Adding simple check for VTK writing if the module is present Removing centroids from the statepoint file and Python UM class Updating test check for vtk Adding warning for skipped elements. Correcting element type Adding warning for skipped elements. Using an enum to indicate element types for readability Updating to element types on the Python side as well Handling integer data applied to VTK files. Doc updates for Python API UM class Incrementing statepoint version number Refactor of unstructured mesh tests to extract model Updating inputs for floating point surface coefficients Adding test for hexes and refactoring comparison funcs Updating reference mesh files Adding reference file for the hexes test case Passing test for hex mesh Adding inputs for the hexes test case. Adding hex test meshes. Skipping hex mesh test if not built with libmesh Adding small VTK write tests for unstructured mesh. Allowing file path to be a pathlib path. Adding skips if libmesh or dagmc not enabled Adding a few comments to test file Changing where conversion to str happens for mesh filename. Setting output to false. Removing VTK check from unstructured mesh regression test Removnig VTK test files for regression test -- too large Adding __init__.py file for pytest
2022-05-31 08:33:43 -05:00